1. Installing Nodejs
2. Installing GRUNT-CLI
Install -G grunt-cli
3. Go to the project directory and prepare the Package.json and gruntfile.js files as well.
// Package.json file content, where alias specifies the path to jquery, and the latter is the grunt plugin that needs to be used { "name": "Seajs_test", "version": "1.0.0", "SPM":{ "alias" : { "jquery": "Lib/jquery-debug" } }, "Devdependencies": { "Grunt": "^0.4.5", "Grunt-cmd-transport": "~0.3.0", "Grunt-cmd-concat": "~0.2.5" , " Grunt-contrib-uglify ":" ~0.2.4 ", " Grunt-contrib-clean ":" ~0.5.0 " }}
//gruntfile.js File ContentsModule.exports =function(Grunt) {Grunt.initconfig ({Pkg:grunt.file.readJSON (' Package.json '), Transport: {options: {paths: [' JS '],//where is the module, and default value is [' Sea-modules ']Alias: ' <%= pkg.spm.alias%> '}, HelloWorld: {options: {idleading :' Helloworld/'}, files: [{cwd:' Js/helloworld ', SRC:' **/*.js ', dest:'. Build/helloworld '}]}, main: {options: {idleading:' Main/'}, files: [{cwd:' Js/main ', SRC:' **/*.js ', dest:'. Build/main '}]}, Lib: {options: {idleading:' lib/'}, files: [{cwd:' Js/lib ', SRC:' **/*.js ', dest:'. Build/lib '}]}, Concat: {options: {include:' Relative '}, Build: {files: {' Dist/helloworld/klass.js ': ['. Build/helloworld/klass.js ', '. Build/helloworld/circle.js '], ' Dist/main/index.js ': ['. Build/main/index.js '], ' Dist/lib/jquery-debug.js ': ['. Build/lib/jquery-debug.js ']}}, Uglify: {main: {files: {' Dist/helloworld/klass.js ': [' dist/helloworld/klass.js '], ' Dist/main/index.js ': [' dist/main/index.js '], ' Dist/lib/jquery-debug.js ': [' dist/lib/jquery-debug.js ']}}, Clean: {build: ['. Build ']//Clean . Build directory } }); Grunt.loadnpmtasks (' Grunt-cmd-transport '); Grunt.loadnpmtasks (' Grunt-contrib-concat '); Grunt.loadnpmtasks (' Grunt-contrib-uglify '); Grunt.loadnpmtasks (' Grunt-contrib-clean '); Grunt.registertask ("Test", "My Custom Task",function() {Console.log ("Hello Grunt"); }); Grunt.registertask (' Default ', [' Transport ', ' concat ', ' uglify ', ' clean ', ' test ']);};
4. Execution of commands
Grunt Default
Where default is the last task name defined by Gruntfile.
5. Project directory Structure