Last active
December 14, 2015 19:59
-
-
Save Johnqing/5140671 to your computer and use it in GitHub Desktop.
gruntjs 0.4和前一个版本0.3,有一些区别,这里是完整的安装过程,转发请带出处,谢谢!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(注意:本教程前提为未安装gruntjs其他版本,如果安装请删除!) | |
1.安装node(在此不做介绍) | |
2.运行命令: npm install -g grunt-cli(-g为全局安装,可在任何目录运行) | |
3.进入项目目录,运行命令: npm install grunt --save-dev | |
4.查看是否安装成功 grunt -version | |
成功显示: grunt-cli v0.1.6 grunt v0.4.0 | |
5.新建package.json | |
如下: | |
{ | |
"name": "51", | |
"version": "0.1.0", | |
"devDependencies": { | |
"grunt": "~0.4.0", | |
"grunt-contrib-jshint": "~0.1.1", | |
"grunt-contrib-uglify": "~0.1.2", | |
"grunt-contrib-concat": "~0.1.1" | |
} | |
} | |
6.在项目根目录运行命令: npm install (不带模块名会安装一些基础模块,npm install xx --save-dev) | |
7.查看项目中node_modules目录,是否包含 | |
grunt | |
grunt-contrib-concat | |
grunt-contrib-jshint | |
grunt-contrib-uglify | |
8.新建Gruntfile.js,结构如下: | |
module.exports = function(grunt) { | |
grunt.initConfig({ | |
concat: { | |
options: { | |
separator: ';' | |
}, | |
dist: { | |
src: ['assets/seajs/seajs.js', assets/init/config.js', 'assets/init/main.js', 'assets/init/category.js', 'assets/init/fimg.js', 'assets/init/lazyload.js'], | |
dest: 'dist/built.js' | |
} | |
} | |
}); | |
//载入concat模块 | |
grunt.loadNpmTasks('grunt-contrib-concat'); | |
// 注册任务(0.4后貌似需要[]来添加注册模块) | |
grunt.registerTask('default', ['concat']); | |
} | |
9.运行命令:grunt,显示如下: | |
Running "default" task | |
default | |
Done, without errors. | |
10.完成。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment