Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install minified version only

Tags:

I just installed Node with npm to use it for frontend dependency management. I know there is also bower but why would I need another package manager that is built on top of another?

When installing a package, npm seems to always load the full source of the js library into the node_modules directory. Just as it's downloading the complete github repository.

How do I install only the minifed (distribution) version of a javascript lib with npm?

like image 828
Andreas Neumann Avatar asked Aug 22 '14 12:08

Andreas Neumann


People also ask

How do I change npm to specific version?

You can downgrade the npm version by specifying a version in the related commands. If you want to downgrade npm to a specific version, you can use the following command: npm install -g npm@[version. number] where the number can be like 4.9. 1 or 8 or v6.

Should npm package be Minified?

Although minification is not always necessary, it is usually your responsibility to transpile any code that is unlikely to be 100% compatible with the target environments of your package audience.

How do I minify a package?

Simply copy + paste the code starting with cat, including the EOT on the last line, and press . Use the command minify followed by the path to and name of the js file intended to be minified. This will minify the code and output it to the screen.

Does npm install globally or locally?

Usually you install NPM modules globally if you want them included in your path to be ran from the command line. Since it is installed locally you will have to run it from the node_modules folder.


1 Answers

There is no standard way to ask npm to get the minified version of a library. Some developers will produce packages that contain both minified and unminified versions (that's what I've done for one of my projects, which is web-only but can be installed through npm) or will create a package that contains an unminified version and another package that contains the minified version. This is done on a case by case basis, varies from package to package, and has to be determined by looking at a project's documentation.

If a developer has not cared to provide a minified code base through npm then you'll have to perform the minification yourself or get the "official" minified code through some other means.

like image 104
Louis Avatar answered Sep 21 '22 22:09

Louis