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": "s-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.
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": "s-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.
Share Improve this question asked May 3, 2016 at 9:13 dagda1dagda1 29k67 gold badges255 silver badges477 bronze badges 3-
That's a front-end application, you don't need the
node_modules
folder on the server. And if you really need those packages, you can deploy thepackage.json
file and install the dependencies on your server. – Ram Commented May 3, 2016 at 9:20 -
@Vohuman Most of the case I agree with you and I do feel like it is the case here. However it may not always be true. It depends how he is building his app. One may choose not to embed some libraries, and use the
node_module
dist instead if it is browser patible. – Quentin Roy Commented May 3, 2016 at 9:25 - How can I exclude karma and phantom for production? – dagda1 Commented May 3, 2016 at 9:27
3 Answers
Reset to default 4there is flag --production to npm install. In an production env you could install npm i --production
this will skip all devDependencies. https://www.npmjs/doc/misc/npm-config.html#production
Another prossibility is 'tree shaking' with rollup.js or babel. Check this here: http://www.2ality./2015/12/webpack-tree-shaking.html
Have you thought about building/piling/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 piling - 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.
Have a look at node-prune:
node-prune
is a small tool to prune unnecessary files from./node_modules
, such as markdown, typescript source files, and so on.
This could be bined with other provided solutions and be made part of your build process.