Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing command line arguments to webpack.config.js

I have a simple webpack.config.js

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

And I want to pass the values for entryand output through command line arguments. Is that possible and how would I do that?

like image 364
user1934212 Avatar asked May 22 '17 12:05

user1934212


1 Answers

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 
like image 199
Axnyff Avatar answered Oct 10 '22 10:10

Axnyff