当前位置: 动力学知识库 > 问答 > 编程问答 >

How to remove npm files from meteor build

问题描述:

After upgrading Meteor to 1.3.x version NPM really came to play. But as always there is back side of the coin: build size.

On meteor 1.2.x build size is ~50MB, ~7k files

On meteor 1.3.x build size is ~190MB, ~27k files.

Twenty seven thousand files. That's quite a number. Not to mention path size exceeding 256 (a trouble for windows users).

I've dig into what meteor included into the build and it seems that all the npm_modules is here with all the stuff that is need to build some modules and their dependencies.

The question is: how to build meteor app without unnessesary npm files, leaving only the ones that are actually used by app at runtime?

Update:

On meteor 1.4.1_3 if you create a simple project meteor create dummy-project and go through all the common stuff like npm meteor install and meteor npm prune --production and them make a bundle out of it with meteor build c:\dummy --directory you will get a folder with the same 7k files and almost 2k folders (by the way it will not run node main.js out of the box as you might expect). If you tinker through folders you can find babel compiler inside that takes ~3.5k files.

Why do I need babel compiler inside compiled app?

网友答案:

To gain an introspective of your packages,

npm list --depth 0 

to see the current packages in your project with only one level.

Inspect that list, and decide if you don't need a package and uninstall it.

You can also use other flags such as

npm list --depth 1 #the number represents the max depth
npm list --long true #for more information about the packages
npm list --global true #to check your global packages. 
npm help-search <searchTerm>

Hope that helps you gain more insight in your packages. help-search Link

You may see that multiple packages depends on the same packages, and then it's up to you to decided what your application needs to run successfully.

Edit 1

You can exclude the packages inside your devDependencies, so that when you're publishing/deploying your code you have a cleaner package.

You do this by using npm prune --production - that removes all your devDependencies, and will require your users to do a npm install for your package to work. For info here

分享给朋友:
您可能感兴趣的文章:
随机阅读: