【问题标题】:webpack - output.filename errorwebpack - output.filename 错误
【发布时间】:2018-01-05 20:50:21
【问题描述】:

我知道这是 webpack 的常见问题;如果无法为您提供有关错误原因或位置的任何信息,则很难进行调试。

我收到了错误:

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

我知道这与某处的语法错误有关,但我对 webpack 太陌生,无法弄清楚。

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

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
};

【问题讨论】:

    标签: javascript webpack webpack-3


    【解决方案1】:

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

    出口应该是你的config:

    module.exports = config;
    

    【讨论】:

    • 就是这样!我看到另一个线程有很多类似的语法建议,但没有一个提到括号问题。
    • 我(错误地)虽然任何一种方式都是可以接受的——带括号或不带括号。此外,如果有人想要一个非弗兰肯斯坦(我已经从上面的 sn-p 中更正了一些事情)示例,说明如何使用无语义的主题实现语义 ui-react,我会使用这个博客,链接到 git 示例:neekey
    猜你喜欢
    • 2018-04-18
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-21
    • 2018-09-18
    • 2017-07-13
    相关资源
    最近更新 更多