package.json

Is it possible to consume environment variables inside of npm / package.json?

爷,独闯天下 提交于 2020-01-14 07:39:09
问题 I'm attempting to build a package.json so that when running a NodeJS app on Heroku it will run the scripts.postinstall step using an environment variable. For example: ... "scripts": { "postinstall": "command $ENV_VAR"} }, ... I've looked at the docs and wasn't able to find something saying I can. Is this even possible? Is this even desirable and "I'm Doing It Wrong"™? 回答1: To answer the last questions, because they're the most important one: yes, no, and absolutely, because you've just

How to pass flags to nodejs application through npm run-script?

ⅰ亾dé卋堺 提交于 2020-01-14 07:26:28
问题 I've a NodeJS file that I run via an "npm" command. I've been trying to list all arguments (including flags). If I run it by directly calling the node exe, it works fine but if I use the npm command, I cannot access the flags. Code: console.dir(process.argv); When I run the file like this, node file.js arg1 arg2 -f --flag2 I can get all of the arguments. [ '/usr/local/bin/node', '/.../file.js', 'arg1', 'arg2', '-f', '--flag2' ] But if I add an npm runner to the package.json file and try to

How can I run multiple npm scripts at the same time?

依然范特西╮ 提交于 2020-01-13 08:58:09
问题 In my package.json , I defined two scripts. How do I run them at the same time? "scripts": { "server": "webpack-dev-server", "webpack": "webpack -wd", }, 回答1: Invoke scripts via npm run with & for parallel execution or with && for sequential execution: npm run server & npm run webpack Explanation: Use && for sequential execution. Use & for parallel execution. 回答2: "scripts": { "sw": "webpack-dev-server & webpack -wd" }, then npm run sw 回答3: You can use a module like parallelshel. https://www

Apply visual styling to echo commands used in npm scripts via package.json

久未见 提交于 2020-01-13 05:57:11
问题 Have recently put together a build tool with npm and package.json scripts, and I have a few echo commands to state which parts of the pipeline are currently running. For example (from my package.json ): { "scripts": { "clean": "rimraf a-directory/", "preclean": "echo \"\n[ Cleaning build directories ]\n\"" } } When I Bash: npm run clean it prints my echo message, and then cleans the appropriate directory. I'd like to change colour, font weight, background text colour to make these echo

Apply visual styling to echo commands used in npm scripts via package.json

佐手、 提交于 2020-01-13 05:57:09
问题 Have recently put together a build tool with npm and package.json scripts, and I have a few echo commands to state which parts of the pipeline are currently running. For example (from my package.json ): { "scripts": { "clean": "rimraf a-directory/", "preclean": "echo \"\n[ Cleaning build directories ]\n\"" } } When I Bash: npm run clean it prints my echo message, and then cleans the appropriate directory. I'd like to change colour, font weight, background text colour to make these echo

Move a module from devDependencies to dependencies in npm package.json

南楼画角 提交于 2020-01-11 15:17:25
问题 Is there any short command to move a module from devDependencies to dependencies in package.json? I find myself always doing this: npm uninstall <module_name> --save-dev npm install <module_name> --save Is there a shorter approach to this? 回答1: Yes! to move a module from devDependencies to dependencies : npm install <module_name> --save-prod 回答2: If you want to do the opposite (i.e. move a module from dependencies to devDependencies ) just do: npm install <module_name> --save-dev or shorthand

Move a module from devDependencies to dependencies in npm package.json

南楼画角 提交于 2020-01-11 15:16:12
问题 Is there any short command to move a module from devDependencies to dependencies in package.json? I find myself always doing this: npm uninstall <module_name> --save-dev npm install <module_name> --save Is there a shorter approach to this? 回答1: Yes! to move a module from devDependencies to dependencies : npm install <module_name> --save-prod 回答2: If you want to do the opposite (i.e. move a module from dependencies to devDependencies ) just do: npm install <module_name> --save-dev or shorthand

Move a module from devDependencies to dependencies in npm package.json

怎甘沉沦 提交于 2020-01-11 15:16:07
问题 Is there any short command to move a module from devDependencies to dependencies in package.json? I find myself always doing this: npm uninstall <module_name> --save-dev npm install <module_name> --save Is there a shorter approach to this? 回答1: Yes! to move a module from devDependencies to dependencies : npm install <module_name> --save-prod 回答2: If you want to do the opposite (i.e. move a module from dependencies to devDependencies ) just do: npm install <module_name> --save-dev or shorthand

use npm with different configuration than package.json

时间秒杀一切 提交于 2020-01-04 07:47:25
问题 I have a complex production environment driven by package.json. The problem: I wish to install locally some additional packages, keep an eye on the list and versions of them. Solution (how to get there): point npm to use another config file, excluded from git, which would keep my private dependencies. Use the file to add packages to local node_modules with npm install . So actually all I need is to change configuration context of npm. I have no clue how to point npm to use a different config

if-else on arguments in npm run script

荒凉一梦 提交于 2020-01-04 02:50:32
问题 I would like to call different other scripts, depending on whether a paramter is given or not: "paramtest": "if [ -z $1 ]; then echo Foo $1; else echo Bar; fi", npm run paramtest should give "Bar". npm run paramtest -- whatever should give "Foo whatever". However in practice I only get: (The parameter is added to the whole line, not 'passed in') > if [ -z $1 ]; then echo Foo; else echo Bar; fi "whatever sh: 1: Syntax error: word unexpected What can I do better? Essentially I am after running