没有搭建环境的,请参考《Grunt自动化构建环境搭建 》,搭建完成后html
新建一个项目目录,这里创建一个“Demo”目录npm
运行CMD,并进入这个目录,运行json
npm install grunt --save-dev
在Demo目录下建立一个GruntFile.js文件,文件内容以下api
module.exports = function(grunt) { grunt.initConfig({ jshint: { files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'], options: { globals: { jQuery: true } } }, watch: { files: ['<%= jshint.files %>'], tasks: ['jshint'] } }); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.registerTask('default', ['jshint']); };
若是要了解GruntFile.js文件信息,请访问http://www.gruntjs.net/api/grunt.file进行详细了解sass
建立package.jsongrunt
npm init
依据提示填写相关信息测试
{ "name": "Demo",//项目名称 "description": "这是一个测试项目",//项目描述 "version": "0.1.0",//项目版本 "author": { "name": "nick4", "email": "nick.yanchen@gmail.com" },//可选 "devDependencies": { "grunt": "^0.4.5", "grunt-contrib-sass": "^0.7.3", "grunt-contrib-uglify": "^0.5.1", "grunt-contrib-watch": "^0.6.1" }//不明确版本可使用*代替 使用--save-dev会自动填写版本 必须 }