--Installation Nodejsinstall Nodejs under Windows, click here, the other system will install the software, Nodejs will be installed, Nodejs installation is very simple.--Installation Gruntusing NPM Global installation, command:npm install-g grunt-cli
--Test compression-NPM initNPM init create Package.json file
join the dependent package. Package.json Content
{ "name": "Demo1", "version": "1.0.0", "description": "", "main": "Index.js", "scripts": { "Test": "Echo \" Error:no test specified\ "&& exit 1" }, "author": "Zwj", "license": "ISC", " Devdependencies ": { " grunt ":" ^0.4.5 ", " Grunt-contrib-jshint ":" ~0.10.0 ", " Grunt-contrib-nodeunit " : "~0.4.1", "grunt-contrib-uglify": "~0.5.0" }}
--NPM installnpm Install to download all dependent packages--Gruntfile fileGruntfile.js
/*2016 August 9 11:32:30 Dynamic Data labels and Ejs templates are similar to <%=%> */module.exports = function (grunt) { grunt.initconfig ({ // Read Package.json file information pkg:grunt.file.readJSON (' Package.json '), //define task uglify: { options: { // Compressed file comment Information banner: '/*! <%= pkg.name%> <%= grunt.template.today ("Yyyy-mm-dd")%> */\n ' }, Build: { //file required to compress src: ' src/<%= pkg.name%>.js ', //Compressed file dest: ' build/<%= pkg.name% >.min.js '}} ); Load the plug-in that contains the "uglify" task. grunt.loadnpmtasks (' grunt-contrib-uglify '); The list of tasks that are performed by default. grunt.registertask (' Default ', [' uglify ']);
--Create files that need to be compressedsrc folder under Demo1.js, the content is copied gruntfile.js the contents of this file.everything is ready.--run-----Pre-run directory:
-----Run:
after-----run:
Create a Build folder automatically and compress the generated demo1.min.js file--Test Merge--then add demo2.js under SRC, same as demo3.js content and demo1.js, then merge the 3 files.--Modify the Gruntfile.js file
/*2016 August 9 11:32:30 Dynamic Data labels and Ejs templates are similar to <%=%> */module.exports = function (grunt) { grunt.initconfig ({ // Read Package.json file information pkg:grunt.file.readJSON (' Package.json '), //define task uglify: { options: { // Compressed file comment Information banner: '/*! <%= pkg.name%> <%= grunt.template.today ("Yyyy-mm-dd")%> */\n ' }, " Files ": { " files ": { ' build/demos.min.js ': [' src/demo1.js ', ' src/demo2.js ', ' src/demo3.js '] } } } }); Load the plug-in that contains the "uglify" task. grunt.loadnpmtasks (' grunt-contrib-uglify '); The list of tasks that are performed by default. grunt.registertask (' Default ', [' uglify ']);
Before------run:
after------run:
nodejs column: Click here
Grunt Plugin list: Click here
Merging front-end code with grunt compression