1、项目目录先写配置项 package.json
{
"name" : "test2",
"version" : "1.0.0",
"author" : "Afei",
"spm": {
"alias": {
"jquery": "../sea-modules/jquery/jquery/1.10.1/jquery.js"
}
},
"devDependencies" : {
"grunt" : "0.4.5",
"grunt-cmd-transport": "~0.3.0",
"grunt-cmd-concat": "~0.2.0",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-clean": "~0.4.0"
}
}
2、再写Gruntfile.js
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
transport:{
options : {
alias: '<%= pkg.spm.alias %>'//引用 package.json 的jq路径
},
test2:{
files:{
'.build':[
'static/helloseajs/src/main.js',
'static/helloseajs/src/mshow.js',
'static/helloseajs/src/mhide.js',
'static/helloseajs/src/indexIn.js',
'static/helloseajs/src/indexOut.js',
'static/helloseajs/src/messageIn.js',
'static/helloseajs/src/messageOut.js',
'static/helloseajs/src/studentsIn.js',
'static/helloseajs/src/studentsOut.js'
]
}
}
},
concat:{
test2:{
files:{
'dist/main.js':[
'.build/static/helloseajs/src/main.js',
'.build/static/helloseajs/src/mshow.js',
'.build/static/helloseajs/src/mhide.js',
'.build/static/helloseajs/src/indexIn.js',
'.build/static/helloseajs/src/indexOut.js',
'.build/static/helloseajs/src/messageIn.js',
'.build/static/helloseajs/src/messageOut.js',
'.build/static/helloseajs/src/studentsIn.js',
'.build/static/helloseajs/src/studentsOut.js'
]
}
}
},
uglify:{
test2:{
files:{
'dist/main.min.js':['dist/main.js']
}
}
},
clean : {
spm : ['.build']
}
});
/**
* 加载插件
* 1、提取id依赖插件
* 2、合并插件
* 3、压缩插件
* 4、删除临时文件插件
*/
// 加载包含 "uglify" 任务的插件。
//
grunt.loadNpmTasks('grunt-cmd-transport');
grunt.loadNpmTasks('grunt-cmd-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-clean');
// 默认被执行的任务列表。
grunt.registerTask('default', ['transport','concat','uglify','clean']);
};
3、npm install // 安装配置的插件
4、grunt //运行grunt