简体   繁体   中英

overriding package.json scripts - NPM

Is there a way to override package.json scripts? I can't change package.json because it will change it for everyone. ie in our package we have

"script": {
    "dev": "yarn dev:build" 
}

I would like to add extra memory for this step as it keeps crashing on my computer. ie

"scripts":{
    "dev": "\"node --max-old-space-size=9000 yarn dev:build\""
}

You can't "override" package.json because the filename is hardcoded in NPM. You can create another script entry like:

"scripts":{
    "dev": "yarn dev:build" 
    "devlocal": "\"node --max-old-space-size=9000 yarn dev:build\""
}

Exclude package.json while committing to whatever SCM you are using, and the modified file would remain local to your machine only.

Having said that, what you are asking for (having another file to do the work of package.json ), is not possible.

It's not technically overriding a script, but you can execute what would be a script without actually adding it to package.json by calling npx in your terminal:

First install npx globally so you can use in any project:

npm install -g npx

Then:

npx --max-old-space-size=9000 yarn dev:build

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM