[英]how to use grunt target
我的Gruntfile.js類似於:
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
grunt.config.set('targ', grunt.option('target'));
cachebuster: {
build: {
options: {
basedir: 'WebContent',
formatter: function(hashes) {
var json = {};
for (var filename in hashes) {
json["/" + filename] = hashes[filename];
}
return JSON.stringify(json);
}
},
src: [ 'WebContent/assets/**/*.js', 'WebContent/assets/**/*.css' ],
dest: 'src/main/resources/cachebusters.json'
}
}
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-cachebuster');
// Default task.
grunt.registerTask('default', ['cachebuster']);
};
我想基於dev更改dest的位置或部署命令行參數。
也就是說,如果命令行arg是dev,那么dest:'cachebuster.json'如果部署了命令行arg,則dest:'src / main / resources / cachebuster.json'
我該如何實現?
您可以嘗試以下代碼塊。 默認情況下,如果不提供任何參數,第一個目標將被執行(在這種情況下為dev):
cachebuster: {
dev: {
options: {
basedir: 'WebContent',
formatter: function(hashes) {
var json = {};
for (var filename in hashes) {
json["/" + filename] = hashes[filename];
}
return JSON.stringify(json);
}
},
src: ['WebContent/assets/**/*.js', 'WebContent/assets/**/*.css'],
dest: 'src/main/resources/cachebusters.json'
},
deploy: {
options: {
basedir: 'WebContent',
formatter: function(hashes) {
var json = {};
for (var filename in hashes) {
json["/" + filename] = hashes[filename];
}
return JSON.stringify(json);
}
},
src: ['WebContent/assets/**/*.js', 'WebContent/assets/**/*.css'],
dest: 'src/main/resources/cachebusters.json'
}
}
如果要跨目標共享選項,請使用以下代碼塊。
cachebuster: {
options: {
basedir: 'WebContent',
formatter: function(hashes) {
var json = {};
for (var filename in hashes) {
json["/" + filename] = hashes[filename];
}
return JSON.stringify(json);
}
},
dev: {
src: ['WebContent/assets/**/*.js', 'WebContent/assets/**/*.css'],
dest: 'src/main/resources/cachebusters.json'
},
deploy: {
src: ['WebContent/assets/**/*.js', 'WebContent/assets/**/*.css'],
dest: 'src/main/resources/cachebusters.json'
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.