user2512231 user2512231 - 3 months ago 37
Node.js Question

run webpack with command line args

I've been trying to pass args from command line to webpack plugin.
I can access the args via process.argv but after that wwebpack fails with error:
ERROR in Entry module not found: Error: Cannot resolve module
It seems that webpack treats the args as folders it needs to find.
This is how I pass the args:
webpack accessKey=myKey

Resolved:

Saw two ways of doing this:


  1. Add the param before calling webpack and use the process.env. to access it:
    For example : myparam=1231 webpack
    in the webpack config file:
    process.env.myparam == 1231

  2. Add the args after the webpack command as flags using --.
    For example : webpack --myparam
    in the webpack config file: process.argv[2] == --myparam



Hopes this helps

Answer

Try passing them before the webpack command:

accessKey=myKey webpack

Comments