我是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答案,但没有一个是适用的,我想我错过了一些明显的东西。
答案 0 :(得分:1)
当减速器转换为ES5时,引入了一个错误。
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") }