U
U
Uncle Vanya2019-04-12 13:24:56
JavaScript
Uncle Vanya, 2019-04-12 13:24:56

How to make arguments in WebPack work?

Hello
, I have the following commands in packaje.json

"test": "echo \"Error: no test specified\" && exit 1",
    "start": "npx webpack --config ./configs/webpack.config.js --watch",
    "server": "node echo_server.js",
    "dev": "concurrently --kill-others \"npm run server\" \"npm run start\""

And webpack.config.js looks like this:
const projectName = process.argv.splice(5)[0];

let file = `./${projectName}.config.js`;
const config = require(file);

module.exports = config;

The idea is this, I write the following on the command line:
npm run start orel
And it enters my config (orel.config.js) and executes the code specified
from
it in this version it looks like this:
Insufficient number of arguments or no entry found.
Alternatively, run 'webpack(-cli) --help' for usage info.


ERROR in Entry module not found: Error: Can't resolve 'orel' in 'C:\Users\Администратор\
Desktop\game\webpack-demo'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Robur, 2019-04-12
@QSem

via "--"
details here https://docs.npmjs.com/cli/run-script

M
Mertico, 2019-04-12
@Mertico

Need to use environment variables
and run PROJECT=bestProject npm run start
And only then catch it in process.env.PROJECT
Or something like this in package
"start": "npx webpack --config ./configs/$PROJECT.config. js --watch",

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question