Building SEAJS projects with grunt

Source: Internet
Author: User

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

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.