【问题标题】:webpack error: output.filename is required, in my ASP.net + Vue appwebpack 错误:在我的 ASP.net + Vue 应用程序中需要 output.filename
【发布时间】:2018-04-18 11:23:58
【问题描述】:

我是 webpack 的初学者,目前我正在关注 @Bert 的 this 回答,在我当前的 MVC 4 应用程序中配置 Vue。

当我尝试运行 webpack --watch 时,出现以下错误:

Error: 'output.filename' is required, either in config file or as --output-filename
    at processOptions (dir\node_modules\webpack\bin\convert-argv.js:507:11)
    at processConfiguredOptions (dir\node_modules\webpack\bin\convert-argv.js:150:4)
    at module.exports (dir\node_modules\webpack\bin\convert-argv.js:112:10)
    at yargs.parse (dir\node_modules\webpack\bin\webpack.js:171:41)
    at Object.Yargs.self.parse (dir\node_modules\webpack\node_modules\yargs\yargs.js:533:18)
    at Object.<anonymous> (dir\node_modules\webpack\bin\webpack.js:152:7)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)

我的 webpack.config.js 文件:

const fs = require("fs");
const path = require("path");

// build an object that looks like 
// {
//      "filename": "./filename.vue"
// }
// to list the entry points for webpack to compile.
function buildEntry() {
    const reducer = function(entry, file) { entry[file.split(".").shift()] = './Vue/' + file; return entry; };

return fs.readdirSync(path.join(__dirname, "Vue"))
    .filter(function(file) {file.endsWith(".vue")})
    .reduce(reducer, {});
}

module.exports = {
    entry: buildEntry(),
    output: {
        path: path.join(__dirname, "Vue"),
        filename: "[name].js",
        library: "[name]"
    },
    module: {
        loaders: [
            { test: /\.vue$/, loader: 'vue-loader' },
        ]
    }
}

我刚刚用 ES5 更改了 ES6 代码,我也遵循了一些关于该问题的现有 SO 答案,但这些答案都不适用,我想我在这里遗漏了一些明显的东西。

【问题讨论】:

    标签: asp.net asp.net-mvc webpack vue.js vuejs2


    【解决方案1】:

    reducer 转为 ES5 时,引入了一个 bug。

    return fs.readdirSync(path.join(__dirname, "Vue"))
    .filter(function(file) {file.endsWith(".vue")})
    .reduce(reducer, {})
    

    具体来说,

    function(file) {file.endsWith(".vue")}
    

    应该是

    function(file) { return file.endsWith(".vue") }
    

    【讨论】:

      猜你喜欢
      • 2018-01-05
      • 1970-01-01
      • 2018-12-25
      • 2021-11-26
      • 2011-11-12
      • 2014-02-07
      • 2020-05-10
      • 2014-06-25
      • 1970-01-01
      相关资源
      最近更新 更多