How to get custom parameters of npm script

such as

 "scripts": {
    "dev": "webpack-dev-server --open  --abc=11111111"
  },

how do I get the value of this abc in JS

Nov.07,2021

webpack supports export in the configuration file webpack.config.js , which accepts two parameters

  • env : environment
  • argv : parameter

all the parameters you pass in are in argv , so you can do this

.
// webpack.config.js
module.exports = (env, argv) => {
    let abc=argv.abc
    return {
    // ...webpack config
    }
}

then start it like this

webpack-dev-server --open  --abc=11111111

if you want to use it in your code, you can use DefinePlugin

.
new webpack.DefinePlugin({
            ABC            : JSON.stringify(abc)
        })

in code

if (ABC==='11111111'){
    alert(abc)
}

const json = require('../../package.json')
console.log(json.scripts)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bea99f-319f4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bea99f-319f4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?