作为一个干净的节点项目,我做了:
npm install webpack copy-webpack-plugin
这是我的webpack.config.js
文件:
var CopyWebpackPlugin = require('copy-webpack-plugin');
var path = require('path');
module.exports = {
plugins: [
new CopyWebpackPlugin([
{
from: 'src',
to: 'dist'
}
])
]
};
当我运行npm run webpack
时收到此错误消息:
$ npm run webpack
> test@1.0.0 webpack /var/www/html/test
> webpack
/var/www/html/test/node_modules/webpack/bin/convert-argv.js:507
throw new Error("'output.filename' is required, either in config file or as --output-filename");
^
Error: 'output.filename' is required, either in config file or as --output-filename
at processOptions (/var/www/html/test/node_modules/webpack/bin/convert-argv.js:507:11)
at processConfiguredOptions (/var/www/html/test/node_modules/webpack/bin/convert-argv.js:150:4)
at module.exports (/var/www/html/test/node_modules/webpack/bin/convert-argv.js:112:10)
at yargs.parse (/var/www/html/test/node_modules/webpack/bin/webpack.js:171:41)
at Object.Yargs.self.parse (/var/www/html/test/node_modules/yargs/yargs.js:533:18)
at Object.<anonymous> (/var/www/html/test/node_modules/webpack/bin/webpack.js:152:7)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
周围没有具体的解决方案。怎么解决呢?
答案 0 :(得分:2)
尝试在webpack.config.js
中添加entry
和output
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const rootPath = path.join(__dirname, '/');
module.exports = {
entry: {
main: `${rootPath}/src/main.js`,
},
output: {
filename: '[name].[hash].js',
path: `${rootPath}/dist`,
},
plugins: [
new CopyWebpackPlugin([
{
from: 'src',
to: 'dist'
}
])
]
};
希望这可以帮助你。