
cssnano comes with a bunch of built-in techniques for making CSS smaller, and autoprefixer adds those -webkit or -moz prefixes where necessary to make your CSS compatible with all browsers.
#NPM MINIFY HOW TO#
Postcss is what we’re using the do the minifying, and cssnano and autoprefixer are plugins for PostCSS that tell PostCSS how to manipulate the CSS.
#NPM MINIFY INSTALL#
Hopefully this article got you to first base! Helpful Links for the uglify-js Node.We’ll be using PostCSS to easily minify a string of CSS in a Node.js script.įirst, install the necessary packages: npm install postcss cssnano autoprefixer But if you want to understand the true power of uglify-js, there is a ton of documentation available online. For this article, I wanted to demonstrate how easy it is to set up and use this Node,js module. The uglify-js offers a ton of options, parameters and features. postcss is what we’re using the do the minifying, and cssnano and autoprefixer are plugins for PostCSS that tell PostCSS how to manipulate the CSS. First, install the necessary packages: npm install postcss cssnano autoprefixer.
#NPM MINIFY CODE#
You can take the same exact steps to demo this example, and when you do, you will see that the file contains the minified code of file-1.js, file-2.js and file-3.js. We’ll be using PostCSS to easily minify a string of CSS in a Node.js script. In this case all of the files are in the same folder as our program, so there is no folder structure (i.e. Each element in the array is a path to a file we want to minimize and the concatenate to the output file. Within that folder should be the minified version of the index.html file initially created. As a result a new folder called 'dist' should have been created where the src folder is located. Instead of passing it a string, we pass an array. Now that the html-minify script is added and the options are configured, to use it run the command npm run html-minify. npm install -g clean-css-cli uglifycss js-beautify html-minifier. The only change we have made is in the call to UglifyJS.minify. Minify for Sublime Text allows you to quickly minify and/or beautify CSS, JavaScript. npm install grunt-contrib-cssmin -save-dev. Execute the following command in a terminal prompt: node uglify-2.jsĮxample # 4 shows the contents of uglify-3.js. A brief tutorial on how to minify CSS files with Grunt using the.


You can install the latest version of jQuery with the npm CLI command.


Now notice that after you execute node uglify-2.js in your terminal, there is a new file named:, which is a minified version of file-1.js. Is there something similar to uglify-js for CSS Searching the NPM site has revealed lots of tools such as clean-css for minifying and concatenating CSS files, but they seem to all be intended for use inside your node website, or some of them have build tool versions for gulp or grunt, but not just for using npm as a simple build tool. Here, we’ve moved things into a more real-world context we save the result of the minification to a physical file. In Example # 3, we have the content of uglify-2.js.
