{"id":401,"date":"2019-05-21T10:32:08","date_gmt":"2019-05-21T01:32:08","guid":{"rendered":"http:\/\/localhost:8000\/?p=401"},"modified":"2021-01-23T10:34:38","modified_gmt":"2021-01-23T01:34:38","slug":"node-npm","status":"publish","type":"post","link":"http:\/\/localhost:8000\/2019\/05\/node-npm.html","title":{"rendered":"node.js\u304a\u3088\u3073npm\u306eTips"},"content":{"rendered":"

npm\u3092\u4f7f\u3046\u5fc5\u8981\u304c\u3042\u3063\u305f\u306e\u3067\u3001\u3068\u308a\u3042\u3048\u305a\u8abf\u3079\u3066\u4f7f\u3044\u65b9\u3092\u307e\u3068\u3081\u305f\u3002\u4eca\u5f8c\u3082Tips\u3092\u8ffd\u52a0\u3057\u3066\u3044\u304f\u3002<\/p>\n

\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u65b9\u6cd5<\/h2>\n

nodebrew\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n
brew install nodebrew<\/code><\/pre>\n

Node.js\u304a\u3088\u3073npm\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n
# \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u53ef\u80fd\u306a\u30d0\u30fc\u30b8\u30e7\u30f3\u4e00\u89a7\u3092\u53d6\u5f97\nnodebrew ls-remote\n\n# install-binary\u3092\u914d\u7f6e\u3059\u308b\u30d5\u30a9\u30eb\u30c0\u3092\u4f5c\u6210\nmkdir ~\/.nodebrew\/src\n\n# \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\nnodebrew install-binary v12.2.0\nnodebrew install-binary latest # \u6700\u65b0\u30d0\u30fc\u30b8\u30e7\u30f3\n\n# \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u6e08\u307f\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u4e00\u89a7\u8868\u793a\nnodebrew ls\n\n# \u7279\u5b9a\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306enode\u3092\u6709\u52b9\u5316\u3059\u308b\n nodebrew use v12.2.0\n\n# node\u30b3\u30de\u30f3\u30c9\u306bPATH\u3092\u901a\u3059\nvi ~\/.bash_profile\n+ export PATH=$PATH:~\/.nodebrew\/current\/bin\nsource ~\/.bash_profile\n\n# Node.js\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u78ba\u8a8d\nnode -v\n\n# npm\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u78ba\u8a8d\nnpm -v<\/code><\/pre>\n

npm\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/h2>\n

npm\u306fNode.js\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u30de\u30cd\u30fc\u30b8\u30e3\u30fc\u3067\u3042\u308b\u3002<\/p>\n

\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n
# \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\nnpm install \u30d1\u30c3\u30b1\u30fc\u30b8\u540d1 \u30d1\u30c3\u30b1\u30fc\u30b8\u540d2 \u30d1\u30c3\u30b1\u30fc\u30b8\u540d3@1.2.3\n# \u30b0\u30ed\u30fc\u30d0\u30eb\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\nnpm install -g \u30d1\u30c3\u30b1\u30fc\u30b8\u540d1 \u30d1\u30c3\u30b1\u30fc\u30b8\u540d2 \u30d1\u30c3\u30b1\u30fc\u30b8\u540d3@1.2.3<\/code><\/pre>\n

\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30a2\u30f3\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n
# \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u304b\u3089\u30a2\u30f3\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\nnpm uninstall \u30d1\u30c3\u30b1\u30fc\u30b8\u540d\n# \u30b0\u30ed\u30fc\u30d0\u30eb\u304b\u3089\u30a2\u30f3\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\nnpm uninstall \u30d1\u30c3\u30b1\u30fc\u30b8\u540d<\/code><\/pre>\n

\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u6e08\u307f\u30d1\u30c3\u30b1\u30fc\u30b8\u4e00\u89a7<\/h3>\n
npm ls<\/code><\/pre>\n

npm-root\uff08node_modules\u306e\u30d5\u30a9\u30eb\u30c0\uff09\u306e\u8a2d\u5b9a<\/h3>\n
# node_modules\u306e\u30d5\u30a9\u30eb\u30c0\u3092\u78ba\u8a8d\nnpm root\nnpm root -g\n# node modules\u306e\u30d5\u30a9\u30eb\u30c0\u3092\u5909\u66f4\n# .npmrc\u3067\u3082\u5909\u66f4\u3067\u304d\u308b\u6a21\u69d8\nnpm config set prefix node_modules\u306e\u30d1\u30b9\nnpm config set -g prefix node_modules\u306e\u30d1\u30b9<\/code><\/pre>\n

package.json\u306b\u3088\u308b\u30d1\u30c3\u30b1\u30fc\u30b8\u7ba1\u7406<\/h2>\n

package.json\u306e\u5b9a\u7fa9\u306b\u5f93\u3063\u3066\u307e\u3068\u3081\u3066\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n

\u73fe\u5728install\u3055\u308c\u3066\u3044\u308b\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u5143\u306b\u3001package.json\u3092\u4f5c\u6210\u3059\u308b<\/h3>\n
npm init<\/code><\/pre>\n

package.json\u306e\u30b5\u30f3\u30d7\u30eb<\/p>\n

{\n  "name": "vue-sample",\n  "version": "0.1.0",\n  "private": true,\n  "dependencies": {\n    "core-js": "^2.6.5",\n    "vue": "^2.6.10",\n    (\u7701\u7565)\n  },\n  "devDependencies": {\n    "@vue\/cli-plugin-babel": "^3.7.0",\n    "@vue\/cli-plugin-eslint": "^3.7.0",\n    (\u7701\u7565)\n  }\n}<\/code><\/pre>\n

dependencies<\/code>\u3068devDependencies<\/code>\u306e\u4e8c\u7a2e\u985e\u3042\u308b\u3002<\/p>\n