Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reducing size of node_modules for production

Our deployment process is taking ages and part of that reason is passing the node_modules folder to the production server.

My Package.json looks like this:

{
  "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"
  }
}

I obviously do not want to deploy karma and phantom as part of the production build.

How can I exclude them for deployment and is there anything else I can do to reduce the size of my node_modules folder.

like image 268
dagda1 Avatar asked May 03 '16 09:05

dagda1


2 Answers

there is flag --production to npm install. In an production env you could install npm i --production this will skip all devDependencies. https://www.npmjs.org/doc/misc/npm-config.html#production

Another prossibility is 'tree shaking' with rollup.js or babel. Check this here: http://www.2ality.com/2015/12/webpack-tree-shaking.html

like image 200
nils petersohn Avatar answered Oct 04 '22 02:10

nils petersohn


Have you thought about building/compiling/transpiling the distribution files and only deploying those? I.e. transfer only whats under 'dist' or similar directory.

Looks like you're building a browser facing parts of an application. For such app, the node_modules directory contains mostly build and testing tools that are to be used during compiling - you shouldn't need to transfer those anywhere. What you need though, is angular and jquery and similar, but those npm packages contain a lot of fluff and shouldn't be deployed as is either.

You should create a set of files that are needed by the user's browser only and transfer those to the production server. This is usually what's created in a 'dist' directory during the build.

like image 43
pspi Avatar answered Oct 04 '22 02:10

pspi