gpt4 book ai didi

javascript - 用于开发/生产环境的备用 grunt.js 任务

转载 作者:数据小太阳 更新时间:2023-10-29 05:46:47 25 4
gpt4 key购买 nike

我真的很希望能够拥有一个开发 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

关于javascript - 用于开发/生产环境的备用 grunt.js 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18476252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com