【问题标题】:How can I load two grunt tasks with the same name?如何加载两个具有相同名称的 grunt 任务?
【发布时间】:2012-12-14 12:10:13
【问题描述】:

我正在为一个项目使用 yeoman。

基本上它工作正常,但在构建过程中我想将我的图像文件夹移动到其他地方。

所以我加载了grunt-contrib-copy 任务,它可以让我这样做。但不幸的是,这与 yeoman 内置的复制任务相冲突。

有没有办法在我的Gruntfile.js 中为grunt-contrib-copy 设置别名,以便我可以同时使用它们?

grunt.loadNpmTasks('grunt-contrib-copy');

//Here I need to use "copy" again but not referencing the yeoman task but the grunt-contrib-copy task.
grunt.registerTask('build','intro clean coffee compass mkdirs concat css min replace copy time');

【问题讨论】:

    标签: gruntjs yeoman


    【解决方案1】:

    grunt.renameTask() 可能会在这里为您提供帮助。试试这个:

    // temporarily rename yeoman's copy task
    grunt.renameTask('copy', 'yeomanCopy');
    // load 'copy' from grunt-contrib-copy
    grunt.loadNpmTasks('grunt-contrib-copy');
    // rename it to something other than 'copy'
    grunt.renameTask('copy', 'myCopy');
    // rename yeoman's task back to its original name so nothing breaks
    grunt.renameTask('yeomanCopy', 'copy');
    
    // now use 'myCopy' for your purposes
    // ...
    

    【讨论】:

    • 谢谢,这行得通!虽然我有一些任务检查某个任务是否已经执行过并且不知道它们的重命名的问题:-/
    • 但是你马上把现有的 yeoman 的任务重命名回来了,不是吗?
    • 糟糕,我停止重命名原始任务,当然你是对的。谢谢德米特里!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    • 2022-12-05
    • 2020-01-22
    • 2014-11-12
    • 1970-01-01
    • 2011-06-01
    • 1970-01-01
    相关资源
    最近更新 更多