简体   繁体   English

Webpack不创建输出文件(不使用webpack-dev-server)

[英]Webpack does not create output file (not using webpack-dev-server)

I am using webpack (NOT the dev-server, I know that doesn't output a file), and it is not creating a dist folder or output file. 我正在使用webpack(不是dev-server,我知道它不输出文件),并且它没有创建dist文件夹或输出文件。

I've tried running it directly through webpack (installed globally) and npm run build which uses a locally installed webpack. 我试过直接通过webpack (全局安装) npm run build它,并使用本地安装的webpack npm run build Neither work. 都不起作用。

Here's my config: 这是我的配置:

const path = require('path');

module.exports = {
  entry: {
    app: './src/entry.js',
  },
  output: {
    path: path.join('/dist'),
    filename: '[name].bundle.js',
  },
  module: {
    loaders: [
      {
        test: /\.tsx?$/,
        loader: 'ts-loader',
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loaders: ['ng-annotate'],
      },
      {
        test: /\.js$/,
        exclude: /(node_modules)/,
        loader: 'babel', // 'babel-loader' is also a legal name to reference
        query: {
          presets: ['es2015', 'latest'],
        },
      },
      {
        test: /\.css$/,
        loader: 'style-loader!css-loader',
      },
      {
        test: /\.html$/,
        loader: 'html',
      },
      {
        test: /\.less$/,
        loader: 'style!css!less',
      },
    ],
  },
  resolve: {
    extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js'],
    root: [
      path.resolve('./src'),
      path.resolve('./node_modules'),
    ],
    alias: {
      vendor: path.join('/node_modules'),
    },
    fallback: ['node_modules'],
  },
};

I've attempted to fix the problem by creating the dist folder manually, but that doesn't work either, the file still is not created. 我试图通过手动创建dist文件夹来解决此问题,但这也不起作用,仍然无法创建该文件。

The weird thing is that it DID build the file before, but now it's stopped. 奇怪的是,它之前已DID构建文件,但现在已停止。 I've not changed the output location or the entry file at any point. 我在任何时候都没有更改输出位置或入口文件。

Any suggestions? 有什么建议么?

Your webpack output path is absolute: 您的webpack输出路径是绝对的:

output: {
    path: path.join('/dist'), <----
    filename: '[name].bundle.js',
},

My guess is it's being generated in your root directory. 我的猜测是它在您的根目录中生成。 /dist would mean from the root of your file system, not relative to your project directory. /dist表示从文件系统的根目录开始,而不是相对于项目目录。

It should be: 它应该是:

output: {
    path: path.join('./dist'),
    filename: '[name].bundle.js',
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM