grunt(1)——安装与配置
2014-12-22 09:21
141 查看
1. 安装python 2.7.X
grunt需要使用到nodejs,而nodejs依赖python,下载nodejs对应版本的python
验证安装成功:cmd-->python --version
2. 安装nodejs
预备使用nodejs的npm下载和管理grunt模块
验证安装成功:cmd-->npm --version
3. 安装grunt-cli
安装使用grunt模块的环境
cmd-->npm install -g grunt-cli
验证安装成功:cmd-->grunt --version
(npm默认安装模块路径:C:\Users\Administrator\AppData\Roaming\npm)
4. 在你的项目根目录下
新建package.json、Gruntfile.js文件
示例:
======================================================
package.json:
{
"name":"abc",
"version":"0.1.0",
"author":"xwl",
"private":true,
"devDependencies":{
"grunt":"~0.4.0",
"grunt-contrib-cssmin":"*",
"grunt-contrib-sass":"*",
"grunt-contrib-uglify":"*",
"grunt-contrib-watch":"*",
"grunt-cssc":"*",
"grunt-htmlhint":"*",
"matchdep":"*"
}
}
======================================================
Gruntfile.js:
module.exports = function(grunt){
// Load grunt-*
require("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks);
grunt.initConfig({
pkg:grunt.file.readJSON('package.json'),
uglify: {
build: {
files: {
'build/style/hello.min.js': ['style/hello.js']
}
}
},
watch: {
js: {
files: ['style/hello.js'],
tasks: ['uglify']
}
}
});
// Load the plugin that provides the "uglify" task.
//grunt.loadNpmTasks('grunt-contrib-uglify');
// Default task(s).
grunt.registerTask('default',[]);
//grunt.registerTask('default',['uglify']);
//grunt.registerTask('buildjs',['uglify']);
};
======================================================
5. 在项目根目录下执行cmd
cmd-->npm install
若提示:npm ERR! Error:shasum check failed for ....,可能是网速问题,可以尝试重新执行
验证安装成功:项目根目录下,npm会自动新增文件夹node_modules,并且在里面下载好了package.json中配置的所有模块
6. 开始使用grunt
前提:package.json中书写没有问题且加载的模块下载成功;Gruntfile.js中任务书写没有问题;
在项目根目录下运行:cmd-->grunt
或者本例中配置的watch任务(cmd-->grunt watch,watch监视一个文件的状态并自动执行grunt的模块)
grunt需要使用到nodejs,而nodejs依赖python,下载nodejs对应版本的python
验证安装成功:cmd-->python --version
2. 安装nodejs
预备使用nodejs的npm下载和管理grunt模块
验证安装成功:cmd-->npm --version
3. 安装grunt-cli
安装使用grunt模块的环境
cmd-->npm install -g grunt-cli
验证安装成功:cmd-->grunt --version
(npm默认安装模块路径:C:\Users\Administrator\AppData\Roaming\npm)
4. 在你的项目根目录下
新建package.json、Gruntfile.js文件
示例:
======================================================
package.json:
{
"name":"abc",
"version":"0.1.0",
"author":"xwl",
"private":true,
"devDependencies":{
"grunt":"~0.4.0",
"grunt-contrib-cssmin":"*",
"grunt-contrib-sass":"*",
"grunt-contrib-uglify":"*",
"grunt-contrib-watch":"*",
"grunt-cssc":"*",
"grunt-htmlhint":"*",
"matchdep":"*"
}
}
======================================================
Gruntfile.js:
module.exports = function(grunt){
// Load grunt-*
require("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks);
grunt.initConfig({
pkg:grunt.file.readJSON('package.json'),
uglify: {
build: {
files: {
'build/style/hello.min.js': ['style/hello.js']
}
}
},
watch: {
js: {
files: ['style/hello.js'],
tasks: ['uglify']
}
}
});
// Load the plugin that provides the "uglify" task.
//grunt.loadNpmTasks('grunt-contrib-uglify');
// Default task(s).
grunt.registerTask('default',[]);
//grunt.registerTask('default',['uglify']);
//grunt.registerTask('buildjs',['uglify']);
};
======================================================
5. 在项目根目录下执行cmd
cmd-->npm install
若提示:npm ERR! Error:shasum check failed for ....,可能是网速问题,可以尝试重新执行
验证安装成功:项目根目录下,npm会自动新增文件夹node_modules,并且在里面下载好了package.json中配置的所有模块
6. 开始使用grunt
前提:package.json中书写没有问题且加载的模块下载成功;Gruntfile.js中任务书写没有问题;
在项目根目录下运行:cmd-->grunt
或者本例中配置的watch任务(cmd-->grunt watch,watch监视一个文件的状态并自动执行grunt的模块)
相关文章推荐
- Grunt安装、配置及应用
- Node.js的项目构建工具Grunt的安装与配置教程
- grunt安装、配置、在webstrom中使用
- nodeJs与grunt安装与配置
- Grunt 安装与配置环境
- 配置Nodejs运行环境,安装grunt运行angular项目
- Nodejs 安装 grunt ,Webstorm grunt 配置
- Node.js的项目构建工具Grunt的安装与配置教程
- Grunt安装配置教程:前端自动化工作流
- Grunt配置之 -- JSHint插件安装和配置
- 安装并配置前端自动化工具——grunt
- NodeJs与Grunt在Linux上的安装与配置
- 安装与配置MySQL,phpmyAdmin;安装与测试PHPLIB
- Apache+Mod_perl+Mod_SSL+PHP+Frontpage extension+Apache::ASP 安装配置手册
- 聆听自由的声音----Linux下声卡驱动软件ALSA的安装与配置
- [导入].NET平台下WEB应用程序的部署(安装数据库和自动配置)
- Linux下声卡驱动软件ALSA的安装与配置
- 自己的linux系统安装以及软件配置
- PostgresQL安装与配置(win2003测试通过)
- MY SQL简单安装配置