gpt4 book ai didi

javascript - Grunt.js 模板 : Use the name of the target in a task?

转载 作者:行者123 更新时间:2023-11-29 14:56:00 25 4
gpt4 key购买 nike

我正在尝试在模板中使用目标的名称。应该很简单吧?

我的场景是这样的:

copy:
{
all: {
src: 'commonFiles/**', dest: 'build/<%= grunt.???? =>/common'
},
apple: { ... },
orange:{ ... },
banana:{ ... },
...
}

grunt.registerTask('default', ['apple', 'orange', 'banana']);

grunt.registerTask('apple' , 'copy:all copy:apples ... ... ...');
grunt.registerTask('orange', 'copy:all copy:orange ... ... ...');
grunt.registerTask('banana', 'copy:all copy:banana ... ... ...');
grimt.registerTask(...);
...
many, many more fruit

我已经搜索了文档,我已经使用 console.log 进行了 grunt 但没有找到作为父任务的字符串。我找到的最接近的是 grunt.task.current.name 但最终是 copy:all

目标是为我所有的水果获得这样的目录结构:

build/apple/common/...
build/orange/common/...
build/banana/common/...
build/.../common/...
...
commonFiles/...

我会把晒好的水果送给能解决这个问题的人。

最佳答案

动态别名任务可能更适合此用例。参见 http://gruntjs.com/frequently-asked-questions#dynamic-alias-tasks

grunt.initConfig({
buildDir: 'all',
copy: {
all: {
src: 'commonFiles/**',
dest: 'build/<%= buildDir =>/common',
},
apple: { ... },
orange:{ ... },
banana:{ ... },
},
});

grunt.registerTask('build', function(target) {
if (target == null) {
return grunt.warn('Build target must be specified, like build:apple.');
}
grunt.config('buildDir', target);
grunt.task.run('copy:' + target);
});

关于javascript - Grunt.js 模板 : Use the name of the target in a task?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17736457/

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