webpack - output.filename错误

时间:2017-07-30 04:10:51

标签: javascript webpack webpack-3

我知道这是webpack的常见问题;如果它不能提供有关错误原因或位置的任何信息,那么调试某些内容真的很难。

我收到了错误:

Error: 'output.filename' is required, either in config file or as --output-filename

我知道它与某处的语法错误有关,但我对webpack来说太新了。

这是我的配置文件。它在根文件夹中称为“webpack.config.js”(即我最初运行的文件夹:npm init)。

const webpack = require('webpack');
const path = require("path");
const ExtractTextPlugin = require("extract-text-webpack-plugin")
const RewriteImportPlugin = require("less-plugin-rewrite-import");

const root_dir = path.resolve(__dirname)
const src_dir = path.resolve(__dirname, "webpack_src")
const build_dir = path.resolve(__dirname, "webpack_bin")
const node_mod_dir = path.resolve(__dirname, 'node_modules');
const extractLESS = new ExtractTextPlugin('style.css');

const config = {
  entry: {
    index: path.resolve(src_dir, 'index.js')
  },
  output: {
    path: build_dir,
    filename: 'bundle.js'
  },
  resolve: {
    modules: [root_dir, 'node_modules'],
  },
  module: {
    rules: [
      {
        loader: 'babel-loader',
        test: /\.(js)$/
      },
      {
        use: extractLESS.extract({
          fallback: 'style-loader',
          use: [
            'css-loader',
            {
              loader: 'less-loader',
              options: {
                paths: [root_dir, node_mod_dir],
                plugins: [
                  new RewriteImportPlugin({
                    paths: {
                      '../../theme.config': __dirname + '/semantic_ui/theme.config',
                    }
                  })
                ]
              }
            }]
        }),
        test: /\.less$/
      },
      {
        use: ['file-loader'],
        test: /\.(png|jpg|gif|woff|svg|eot|ttf|woff2)$/
      },
    ]
  },
  plugins: [
    extractLESS,
    new webpack.optimize.ModuleConcatenationPlugin()
  ]
};

module.exports = {
  config
};

1 个答案:

答案 0 :(得分:1)

您正在导出module.exports = { config },这意味着您正在导出具有一个属性的对象,即config,但webpack希望该对象成为您的整个配置。 Webpack需要output.filename,而您只提供config.output.filename

导出应该是您的config

module.exports = config;