Merging front-end code with grunt compression

Source: Internet
Author: User

--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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.