Passing command line arguments to webpack.config.js

前端 未结 4 786
甜味超标
甜味超标 2021-01-03 17:44

I have a simple webpack.config.js

module.exports = {
  entry: \"./app.js\",
  output: {
    filename: \"bundle.js\"
  },
}

And I want to p

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-03 18:17

    You can provide custom parameters on the env variable from the command line, so for this example you could call:

    webpack --env.entry='./app.js' --env.output='bundle.js'

    and use them in your webpack by doing

    module.exports = env => ({
      entry: env.entry,
      output: {
        filename: env.output
      },
    });
    

提交回复
热议问题