用于开发/生产环境的交替grunt.js任务
Alternate grunt.js tasks for development/production environments
我真的很想拥有一个开发grunt文件,并使用同一个文件作为脚本的生产版本。
我已经在SO上尝试过这个建议,但我的脚本在尝试调用dev/prod参数时会失败。我相信答案是针对grunt的旧版本,或者可能是我正在使用的插件。
module.exports = function (grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
compass: {
dev: {
options: {
config: 'config.rb',
force: true,
livereload: true
}
}
},
uglify: {
build: {
src: ['docroot/js/*.js', 'docroot/components/**/*.js'],
dest: 'docroot/dis/main.min.js'
}
},
watch: {
options: {
dateFormat: function(time) {
grunt.log.writeln('The watch finished in ' + time + 'ms at' + (new Date()).toString());
grunt.log.writeln('Waiting for more changes...');
},
livereload: true
},
sass: {
files: ['docroot/sass/*.scss'],
tasks: ['compass:dev']
},
/* watch and see if our javascript files change, or new packages are installed */
js: {
files: '<%= uglify.build.src %>',
tasks: ['uglify']
},
/* watch our files for change, reload */
livereload: {
files: ['*.html', 'docroot/css/*.css', 'docroot/img/*', 'docroot/js/{main.min.js, plugins.min.js}'],
options: {
livereload: true
}
}
}
});
grunt.registerTask('default', 'watch');
};
真的,只要我能通过调用它们来运行两个版本,例如:
grunt //local
grunt prod //live
然后我就可以玩脚本和加载什么了。
您也可以只注册一个调用任务数组的任务
grunt.registerTask('prod', ['tasks1','task2']);
在你的默认任务之前,那将是
$ grunt prod
相关文章:
- 如何将package.json数组传递给grunt.js
- 你能把grunt.js中的linter改成jslint吗
- 如何在Grunt.js中观察多个文件,但只在更改的文件上运行任务
- 有没有一种方法可以在windows上使用Grunt.js调用gitshell中的命令
- 编程控制Grunt.js
- Grunt.js:我如何自己规范文件,就像Grunt那样
- grunt.js - 将 JavaScript 连接到函数调用中
- 如何使用 Grunt.js在 bootstrap.less 中注入外部 .less 文件
- Grunt.js & uglify 将丑陋的代码附加到文件中,而不是重写它
- 你能查看你编译/执行的grunt.js文件吗
- Grunt.js没有处于监视模式
- 用于开发/生产环境的交替grunt.js任务
- 如何让Grunt.js和Meteor.js协同工作
- Grunt JS如何瞄准*所有文件夹
- Grunt.js的基本用法:如何创建正确的目录结构
- Grunt.js:htmlhint-针对所有html文件
- Grunt.js模板:在任务中使用目标的名称
- JSHint和grunt.js-未定义Highcharts
- 如何配置Grunt.js文件以在构建过程中复制没有特定子目录的目录
- 让Grunt.js运行node.js模块