Reputation: 9635
I have a webpack config with currently three parameters, which works when I invoke it in the following way:
webpack --env.p1 = "p1_value" --env.p2 = "p2_value" --env.p3 = "p3_value"
Now I want to encapsulate that webpack command in the following package.json script:
"scripts": {
"prod": "webpack --env.p1 --env.p2 --env.p3"
}
How do I have to change that script such that I can invoke it from the CLI in the following way
npm run prod p1="p1_value" p2="p2_value" p3="p3_value"
(where the named parameters are indispensible, because I need to be able to work with default values inside the webpack config?)
Upvotes: 2
Views: 2307
Reputation: 20236
You can pass any arguments provided to the npm command through to webpack using the placeholder ${@:1}
.
package.json
"scripts": {
"prod": "webpack ${@:1}"
}
From the command line, add parameters to be passed through using --
as separator, like so:
npm run prod -- --env.p1="p1_value" --env.p2="p2_value" --env.p3="p3_value"
Upvotes: 3