[英]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. 我们的部署过程node_modules
,部分原因是将node_modules
文件夹传递到生产服务器。
My Package.json
looks like this: 我的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"
}
}
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. 我如何排除它们进行部署,还有什么我可以做的事以减小node_modules文件夹的大小。
there is flag --production to npm install. 在npm install上有--production标志。 In an production env you could install npm i --production
this will skip all devDependencies. 在生产环境中,您可以安装npm i --production
这将跳过所有devDependencies。 https://www.npmjs.org/doc/misc/npm-config.html#production https://www.npmjs.org/doc/misc/npm-config.html#production
Another prossibility is 'tree shaking' with rollup.js or babel. 另一个优点是使用rollup.js或babel进行“摇晃”。 Check this here: http://www.2ality.com/2015/12/webpack-tree-shaking.html 在这里检查: http : //www.2ality.com/2015/12/webpack-tree-shaking.html
Have you thought about building/compiling/transpiling the distribution files and only deploying those? 您是否考虑过构建/编译/编译分发文件并仅对其进行部署? Ie transfer only whats under 'dist'
or similar directory. 即只转移'dist'
或类似目录下的内容。
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. 对于此类应用程序, node_modules
目录主要包含将在编译期间使用的构建和测试工具-您无需将这些工具转移到任何地方。 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. 但是,您需要的是angular和jquery以及类似的东西,但是这些npm软件包包含很多绒毛,也不应该按原样部署。
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. 这通常是在构建过程中在'dist'
目录中创建的。
Have a look at node-prune : 看看node-prune :
node-prune
is a small tool to prune unnecessary files from./node_modules
, such as markdown, typescript source files, and so on.node-prune
是从./node_modules
修剪不必要的文件(例如markdown,打字稿源文件等)的小工具。
This could be combined with other provided solutions and be made part of your build process. 可以将其与其他提供的解决方案结合起来,并成为构建过程的一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.