- 安装nodejs,去nodejs的官网下载nodejs,我使用的是第一个如下图所示:
- 安装grunt-cli
npm install -g grunt-cli - 建立grunt文件夹,在文件夹下面建立package.json、Gruntfile.js文件
- 安装grunt
npm install grunt - 安装grunt插件
npm install grunt-contrib-uglify、grunt-contrib-jshint、grunt-contrib-concat
- 最后执行grunt就ok了
- package.json:
{ "name": "xcwJs", "version": "0.1.0", "description": "xcwJs", "devDependencies": { "grunt": "~0.4.1", "grunt-contrib-jshint": "~0.6.3", "grunt-contrib-uglify": "~0.2.1", "grunt-contrib-requirejs": "~0.4.1", "grunt-contrib-concat": "~0.1.1", "grunt-contrib-copy": "~0.4.1", "grunt-contrib-clean": "~0.5.0", "grunt-strip": "~0.2.1" }, "dependencies": { "express": "3.x" } }
- Gruntfile.js
module.exports = function (grunt) { // ÏîÄ¿ÅäÖà grunt.initConfig({ pkg: grunt.file.readJSON(‘package.json‘), concat: { options: { separator: ‘;‘ }, dist: { //要合并的文件 src: [‘src/addfavor.js‘, ‘src/arrayHelp.js‘, ‘src/common.js‘,‘src/convertor.js‘,‘src/slider.js‘,‘src/star.js‘,‘src/vTicker.js‘], dest: ‘dest/xcw.js‘//将文件合并到dest下 } }, uglify : { options : { //压缩文件的头部说明 banner : ‘/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n‘ }, build : { src : ‘dest/xcw.js‘, dest : ‘dest/xcw.min.js‘ } } }); // 载入concat和uglify插件,分别对于合并和压缩 grunt.loadNpmTasks(‘grunt-contrib-concat‘); grunt.loadNpmTasks(‘grunt-contrib-uglify‘); // 注册任务 grunt.registerTask(‘default‘, [‘concat‘, ‘uglify‘]); }
时间: 2024-11-05 15:53:49