- 安装 node.js
将 gruntfile.js 和 package.json 添加到项目的根目录(在 gruntfile.js 中根据需要修改文件的路径(可能需要在 textpad 中打开,因为在 Visual Studio 中可能不显示)
打开 Node.js 终端(命令提示符)并转到项目目录
类型:
npm install grunt-ts --save [按回车]
npm install grunt-cli -g [按回车]
咕噜 [按回车]
(如果缺少模块,请输入: npm install [module name] )
例如 npm install grunt-contrib-uglify npm install grunt-contrib-watch
然后输入咕噜
只要javascript文件丢失错误,就应该缩小文件而没有错误(通过jsHint.com运行)
这是我的 gruntfile.js .....
module.exports = function (grunt) {
// 1. All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
css: {
src: ['archive/trunk_archived_16_06/Grouptree.UI.Web/UI.core/assets/css/*.css'],
dest: 'archive/trunk_archived_16_06/Grouptree.UI.Web/UI.core/assets/css/production.css'
},
js: {
src: ['archive/trunk_archived_16_06/Grouptree.UI.Web/UI.core/assets/js/*.js'],
dest: 'archive/trunk_archived_16_06/Grouptree.UI.Web/UI.core/assets/js/production.js'
}
},
cssmin: {
css: {
src: 'archive/trunk_archived_16_06/Grouptree.UI.Web/UI.core/assets/css/production.css',
dest: 'archive/trunk_archived_16_06/Grouptree.UI.Web/UI.core/assets/css/min/production.min.css'
}
},
uglify: {
js: {
src: 'archive/trunk_archived_16_06/Grouptree.UI.Web/UI.core/assets/js/production.js',
dest: 'archive/trunk_archived_16_06/Grouptree.UI.Web/UI.core/assets/js/min/production.min.js'
}
},
watch: {
css: {
files: ['archive/trunk_archived_16_06/Grouptree.UI.Web/UI.core/assets/css/*.css'],
tasks: ['concat:css', 'cssmin:css']
},
js: {
files: ['archive/trunk_archived_16_06/Grouptree.UI.Web/UI.core/assets/js/*.js'],
tasks: ['concat:js', 'uglify:js']
}
}
});
// 2. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
// 3. Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask('default', ['concat', 'cssmin', 'uglify']);
};
这是我的 package.json 文件
{
"name": "Grunt",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-concat": "^0.4.0",
"grunt-contrib-cssmin": "^0.10.0",
"grunt-contrib-uglify": "^0.5.0",
"grunt-contrib-watch": "*"
},
"dependencies": {
"grunt": "^0.4.5",
"grunt-ts": "^1.11.13"
}
}