javascript - 减少用于生产的 node_modules 的大小

标签 javascript node.js

我们的部署过程需要很长时间,部分原因是将 node_modules 文件夹传递到生产服务器。

我的 Package.json 看起来像这样:

{
  "name": "coms-sass",
  "version": "0.0.1",
  "description": "Sass gulp task for COMS Service Portal",
  "main": "gulpfile.js",
  "dependencies": {
    "angular": "^1.5.5",
    "angular-sanitize": "=1.5.5",
    "angular-ui-bootstrap": "^1.3.2",
    "gridster": "^0.5.6",
    "gulp": "^3.9.0",
    "gulp-jshint": "^2.0.0",
    "gulp-sass": "^2.0.4",
    "jasmine-core": "^2.4.1",
    "jquery": "^2.2.3",
    "jquery.cookie": "^1.4.1",
    "jshint": "^2.9.1",
    "jshint-visual-studio": "^1.0.1",
    "karma": "^0.13.22",
    "karma-chrome-launcher": "^0.2.2",
    "karma-phantomjs-launcher": "^1.0.0",
    "karma-requirejs": "^0.2.6",
    "lodash": "^4.6.1",
    "moment": "^2.13.0",
    "ng-csv": "^0.3.6",
    "requirejs": "^2.1.0",
    "bootstrap":  "=3.3.5" 
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "angular-mocks": "^1.5.5",
    "karma-jasmine": "^0.3.8",
    "karma-ng-html2js-preprocessor": "^0.2.1",
    "karma-phantomjs-launcher": "^1.0.0",
    "karma-requirejs": "^0.2.6",
    "phantomjs": "^2.1.3",
    "phantomjs-prebuilt": "^2.1.6"
  }
}

我显然不想将 karma 和 phantom 部署为生产构建的一部分。

我如何将它们排除在部署之外,还有什么我可以做的来减少我的 node_modules 文件夹的大小。

最佳答案

npm install 有 --production 标志。在生产环境中,您可以安装 npm i --production 这将跳过所有 devDependencies。 https://www.npmjs.org/doc/misc/npm-config.html#production

另一种可能性是使用 rollup.js 或 babel 进行“tree shaking”。在这里检查:http://www.2ality.com/2015/12/webpack-tree-shaking.html

关于javascript - 减少用于生产的 node_modules 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37000129/

相关文章:

node.js - 如何更改restify中的默认错误输出

mysql - 添加并返回当前日期 NodeJs

javascript - 尝试获取 request.body Nodejs 中的所有字段时出现异常 "Object.keys called on non-object while trying to access object"?

node.js - Nodejs 同步请求不返回 HTML 响应

javascript - 使用 lodash 过滤深层嵌套对象数组无法正常工作

javascript - 在 react 中将参数传递给父组件回调的正确方法

javascript - Javascript 中的重复手动幻灯片

javascript - 在 HTML 中放置条件

javascript - ionic 电容器网络错误 "at t.exports (http://localhost/js/chunk-vendors.6faaceee.js:7:66512)\n "使用 Android 模拟器

Node.js 的 Json 解析问题