Passing command line arguments to webpack.config.js

前端 未结 4 785
甜味超标
甜味超标 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:10

    webpack.config.js can also exports a function of env which can return a conf object. You can therefore have a webpack config like:

    module.exports = env => {
        return {
            entry: env === "production" ? "./app.js": "app-dev.js",
            output: {
              filename: "bundle.js"
            },
        }
    };
    

    and then call webpack from command-line (or package.json) like this:

    webpack --env=production
    

提交回复
热议问题