I have a scripts folder in which many individual scripts inside seperate folder, I would like to build each separately via passing the script name as parameter.
I have set up rollup in package.json like "watch": "rollup --watch --config rollup.config.js"
I would like to pass parameter from cli like npm run watch script_name=abc_script
It can be accessible in rollup.config.js via process.argv
But getting this error
rollup v1.23.1
bundles abc_script → dist/bundle.js
[!] Error: Could not resolve entry module
Everything seems fine without npm cli parameter.
Rollup have --environment variable but it's bit long to use npm run watch -- --environment script:script_name
Is there any way to shorten this?
Thanks in advance.
Alternatively, you can pass environment variables to the command - it's much easier to process than command-line arguments.
Cli usage:
minify=on ./node_modules/.bin/rollup -c
package.json script:
{
...
scripts: {
...
"build-production": "minify=on rollup -c"
}
}
rollup.config.js
const enableMinification = process.env.minify === 'on'
You can pass arguments which will be caught by process.argv
like this
npm run watch -- some_arg
In your program, you will get an array in process.argv in this the last value will be the value passed to the program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With