【问题标题】:grunt-babel not working as multi-taskgrunt-babel 不能作为多任务工作
【发布时间】:2016-03-27 21:13:56
【问题描述】:

以下配置按预期工作,但是当 //build: { 未注释时,它要么静默失败,要么做一些令我意想不到的事情。

    babel: {
        //build: {
            options: {
                sourceMap: true,
                presets: ['es2015']
            },
            dist: {
                files: [{
                    expand: true,
                    cwd: 'build/src/app',
                    src: ['**/*.js'],
                    dest: 'build/src/es5-app'
                }]
            }
        //}
    },

因此,注释掉 //build: { 后,es5-app 目录在 build/src 处创建,但 //build: { 未注释时,目录不会创建。在这两种情况下,grunt 都以grunt babel 运行,并返回Done, without errors

【问题讨论】:

    标签: gruntjs babeljs grunt-babel


    【解决方案1】:

    由于 grunt-babel 注册为多任务,dist 实际上是目标的名称,files 位于配置的第一级。所以当你在没有build 的情况下运行 babel 时,它实际上是在运行babel:dist(你应该在日志中看到)。

    要让它按照您想要的方式工作,您需要以下内容:

    babel: {
        options: {
            sourceMap: true,
            presets: ['es2015']
        },
        dist: {
            files: [{
                expand: true,
                cwd: 'build/src/app',
                src: ['**/*.js'],
                dest: 'build/src/es5-app'
            }]
        }
        build: {
            files: [{
                expand: true,
                cwd: 'build/src/app/test',
                src: ['test/**/*.js'],
                dest: 'build/test/es5-app'
            }]
        }
    },
    

    这将允许您运行 babel:dist 或 babel:build。

    有关多任务的更多信息,请参阅http://gruntjs.com/creating-tasks

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-22
      • 2016-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多