Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
webpack copy plugin给出错误:需要output.filename,可以在配置文件中,也可以作为--output filename_Webpack - Fatal编程技术网

webpack copy plugin给出错误:需要output.filename,可以在配置文件中,也可以作为--output filename

webpack copy plugin给出错误:需要output.filename,可以在配置文件中,也可以作为--output filename,webpack,Webpack,作为一个干净的节点项目,我会: 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: '

作为一个干净的节点项目,我会:

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
$npm运行网页包
> test@1.0.0webpack/var/www/html/test
>网页包
/var/www/html/test/node_modules/webpack/bin/convert argv.js:507
抛出新错误(“'output.filename'是必需的,在配置文件中或作为--output filename”);
^
错误:“output.filename”是必需的,在配置文件中或作为--output filename
在processOptions(/var/www/html/test/node_modules/webpack/bin/convert argv.js:507:11)
在processConfiguredOptions(/var/www/html/test/node_modules/webpack/bin/convert argv.js:150:4)中
在module.exports(/var/www/html/test/node_modules/webpack/bin/convert argv.js:112:10)
在yargs.parse(/var/www/html/test/node_modules/webpack/bin/webpack.js:171:41)
在Object.Yargs.self.parse(/var/www/html/test/node\u modules/Yargs/Yargs.js:533:18)
反对。(/var/www/html/test/node_modules/webpack/bin/webpack.js:152:7)
在模块处编译(Module.js:643:30)
在Object.Module._extensions..js(Module.js:654:10)
在Module.load(Module.js:556:32)
在tryModuleLoad时(module.js:499:12)
在Function.Module.\u加载(Module.js:491:3)
位于Function.Module.runMain(Module.js:684:10)
启动时(bootstrap_node.js:187:16)
在bootstrap_node.js:608:3

没有具体的解决办法。如何解决此问题?

尝试在webpack.config.js中添加
条目
输出

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'
      }
    ])
  ]
};
希望这能对你有所帮助