交替开发/生产环境的grunt.js任务 [英] Alternate grunt.js tasks for development/production environments
问题描述
我已经尝试过关于SO的建议了,所以我希望能够有一个开发grunt文件并使用相同的文件生成版本的脚本。但是当我尝试调用dev / prod参数时,我的脚本就会失败。我相信答案是针对旧版本的grunt,或者是我正在使用的插件。
module.exports = function (grunt){
//载入所有grunt任务
require('matchdep')。filterDev('grunt - *')。forEach(grunt.loadNpmTasks);
grunt.initConfig({
pkg:grunt.file.readJSON('package.json'),
指南针:{$ b $ dev:{
选项:{
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('手表在+ + new Date())。'toString());'
grunt.log.writeln('正在等待更多更改...')'+ time +'ms中完成;
},
livereload:true
},
sass:{
文件:['docroot / sass / *。scss'],
任务:['compass:dev']
},
/ *观察并查看我们的JavaScript文件是否更改或新软件包已安装* /
js:{
files:'<%= uglify.build.src%>',
tasks:['uglify']
},
/ *观看我们的文件以进行更改,重新加载* /
livereload:{
files:['* .html','docroot / css / *。css','docroot / img / *','docroot / js / {main.min.js,plugins.min.js}'],
选项:{
livereload:true
}
}
}
});
grunt.registerTask('default','watch');
};
真的,只要我可以通过调用它们来运行两个版本,例如:
grunt // local
grunt prod // live
然后我可以使用脚本和要载入的内容。
p>你也可以注册一个调用任务数组的任务 grunt.registerTask('prod',['tasks1 , 'TASK2']);
在您的默认任务之前,那将是
$ grunt prod
I would really love to be able to have a development grunt file and using the same file an production version of the script.
I have tried the suggestion on SO but my script will just fail when trying to call a dev/prod argument. I believe that the answer is for an older version of grunt, or maybe the plugins I am using.
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');
};
Really, so long as I can get two version running by calling them with, for example:
grunt //local
grunt prod //live
then I can play around with the scripts and what to load.
You can also just register a task that calls an array of tasks
grunt.registerTask('prod', ['tasks1','task2']);
before your default task, that would be
$ grunt prod
这篇关于交替开发/生产环境的grunt.js任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!