Angular的Grunt-shell任务在VS Task Runner Explorer中失败,但在命令提示符下工作

时间:2017-08-03 14:47:43

标签: angular gruntjs visual-studio-2017 task-runner-explorer grunt-shell

我有一个grunt脚本,旨在启动Angular 2版本。

在命令行上运行grunt成功 - Angular构建按预期运行。

在VS 2017中从Task Runner Explorer运行任务失败。

Gruntfile.js如下:

module.exports = function (grunt) {

    grunt.initConfig({

        shell: {
          options: {
            stderr: false
          },
          angularBuild: {
              command: 'ng build --prod'
          }
        }

    });

    grunt.loadNpmTasks('grunt-shell');

    grunt.registerTask('default', ['shell']);
};

Task Runner Explorer中的输出是:

D:\Work> cmd.exe /c grunt -b "D:\Work" --gruntfile "D:\Work\Gruntfile.js" default --color
Running "shell:angularBuild" (shell) task
Warning: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "ng build --prod"
D:\Work\node_modules\@angular\cli\models\config\config.js:17
    constructor(_configPath, schema, configJson, fallbacks = []) {
                                                           ^
SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (D:\Work\node_modules\@angular\cli\models\config.js:3:18)
    at Module._compile (module.js:397:26)
    at Object.Module._extensions..js (module.js:404:10)
Use --force to continue.
Aborted due to warnings.
Process terminated with code 6.

1 个答案:

答案 0 :(得分:0)

感谢Mads Kristensen指出他2岁的博客帖子 - 与命令提示符相比,VS使用了不同版本的工具。

https://blogs.msdn.microsoft.com/webdev/2015/03/19/customize-external-web-tools-in-visual-studio-2015/