Use grunt JS for the link and compression of JS

Source: Internet
Author: User

1,http://nodejs.org/download/installation Nodejs

2. Configure the environment variable to place the installation directory of the Nodejs in the PATH environment variable

3, in cmd in NPM install-g grunt-cli, if already installed, NPM uninstall-g Grunt This sentence can be deleted

4,grunt-version to see if the installation was successful

5, create Package.json in the directory you want to compress

6, a simple sample of Package.json

{
"name": "Umeditor",
"title": "Umeditor",
"description": "Umeditor",
"version": "1.2.2",
" Homepage ":" Https://github.com/fex-team/umeditor ",
" author ": {
" name ":" F-cube @ fex ",
" url ":"/HTTP/ Fex.baidu.com "
},
" repository ": {
" type ":" Git ",
" url ":" Https://github.com/fex-team/umeditor.git "
},
"keywords": [
"Umeditor",
"Web Editor",
"Ueditor",
"JavaScript"
],
"bugs": {
"url" : "Https://github.com/fex-team/umeditor/issues"
},
"dependencies": {
"grunt": "~0.4.1",
" Grunt-contrib-concat ":" ~0.3.0 ",
" grunt-contrib-cssmin ":" ~0.6.0 ",
" Grunt-closurecompiler ":" ~0.9.9 ",
" Grunt-contrib-copy ":" ~0.4.0 ",
" grunt-transcoding ":" ~0.1.1 ",
" Grunt-text-replace ":" ~0.3.9 ",
" Grunt-contrib-compress ":" ~0.7.0 "
},
" Devdependencies ": {
" grunt ":" ~0.4.1 ",
" Grunt-contrib-concat ":" ^0.3.0 ",  
" grunt-contrib-uglify ":" ^0.5.1 "
}
}

7, create Gruntfile.js

A simple example

Module.exports = function (grunt) {

Grunt.initconfig ({

Our Jshint options


Our concat options
Concat: {
Options: {

},
Dist: {
SRC: [' src/*.js '],//grunt mini match for your scripts to concatenate
Dest: ' dest/edit.js '//where to output the script
}
},

Our uglify options
Uglify: {
JS: {
Files: {
' Dest/edit.js ': [' dest/edit.js ']//save over the newly created script
}
}
}

});

Load our Tasks
Grunt.loadnpmtasks (' Grunt-contrib-jshint ');
Grunt.loadnpmtasks (' Grunt-contrib-concat ');
Grunt.loadnpmtasks (' grunt-contrib-uglify ');

Default Tasks to run
Grunt.registertask (' Default ', [' concat ', ' uglify ']);
Grunt.registertask (' development ', [' jshint ']);
Grunt.registertask (' Production ', [' jshint ', ' concat ', ' uglify ']);
}

7, perform NPM install grunt--save-dev to keep the latest grunt in your directory

8, the implementation of the Grunt command on the implementation of packaging

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.