package.jsonã§å¤ãå±éãã
ðä»å¹´åã®è¨äºã§ãð
ããããã°ãããªæ©è½ãã£ããªã¼ã£ã¦æãã ã£ãã®ã§è¨äºã«ãã¦ã¿ã¾ããã
æ¬å½ã¯ä»å¹´æåã®è¨äºç¨æãã¦ããã®ã§ãããã¾ã çµãã£ã¦ãªãã®ã§å¾ã»ã©ãã
ä»åã¯ãã¿ã¹ã¯ã®startã¨buildã«åãå¤æ°ãwebpackã¸æ¸¡ãããã«å ±éåãããã¦ãéãå¤ããªã£ã¦ããã®ã§ãªãã¡ã¯ã¿ãªã³ã°ãã¾ããã
æé
$npm_package_
ã«package.jsonã«æ¸ããkeyãã¤ãªããã¨ããã®valueå±éããã¾ãã
ã³ã³ã½ã¼ã«ä¸ã§ã¯ãå±éããã¾ããããJSä¸ã§ã¯å±éããã¾ãã
// 確èªç¨ã®JS console.log(process.argv[2]);
$ npm run main > node main.js $npm_package_foo bar
æååã®å ´å
{ "foo": "bar", "scripts": { "main": "node main.js $npm_package_foo" } }
ãªãã¸ã§ã¯ãã®å ´å
ãªãã¸ã§ã¯ãã渡ããã¨ã¯ã§ããªãã®ã§ãæ«ç«¯ã¾ã§æå®ããå¿ è¦ãããã¾ãã
{ "foo": { "bar": 1 }, "scripts": { "main": "node main.js $npm_package_foo_bar" } }
ããã$npm_package_foo
ã¨æ¸ããå ´åã¯ãundefined
ã¨ãªãã¾ãã
é åã®å ´å
é åã渡ããã¨ã¯ã§ããªãã®ã§ãæ·»åãæå®ããå¿ è¦ãããã¾ãã
{ "foo": ["bar"], "scripts": { "main": "node main.js $npm_package_foo_0" } }
ããã$npm_package_foo
ã¨æ¸ããå ´åã¯ãundefined
ã¨ãªãã¾ãã
ã¾ã¨ã
$npm_package_
ã¨ãããã¬ãã£ãã¯ã¹ã使ãã- å¿ ãå¤ã¯ããªããã£ãã§ãªããã°ãªãã¾ããã