0

我正在尝试使用 grunt 和 angular 2 构建一个项目。我看到有一个特殊版本的 grunt 支持 ts(grunt ts- https://www.npmjs.com/package/grunt-ts)。

当我尝试使用某些类型脚本文件构建项目时,出现以下错误:

>> 1 syntax error  51 non-emit-preventing type warnings
>> Error: tsc return code: 2
Warning: Task "ts:default" failed. Use --force to continue.

Aborted due to warnings.

谁能帮我解决它?

这是我的配置文件:

包.json

{
  "name": "grunt_quick_start",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "grunt": "^1.0.1",
    "@angular/common":  "2.0.0-rc.1",
    "@angular/compiler":  "2.0.0-rc.1",
    "@angular/core":  "2.0.0-rc.1",
    "@angular/http":  "2.0.0-rc.1",
    "@angular/platform-browser":  "2.0.0-rc.1",
    "@angular/platform-browser-dynamic":  "2.0.0-rc.1",
    "@angular/router":  "2.0.0-rc.1",
    "@angular/router-deprecated":  "2.0.0-rc.1",
    "@angular/upgrade":  "2.0.0-rc.1",
    "systemjs": "0.19.27",
    "core-js": "^2.4.0",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.6",
    "zone.js": "^0.6.12",
    "angular2-in-memory-web-api": "0.0.9",
    "bootstrap": "^3.3.6"

  },
  "devDependencies": {
    "grunt-contrib-clean": "^1.0.0",
    "grunt-contrib-connect": "^1.0.2",
    "grunt-contrib-copy": "^1.0.0",
    "grunt-contrib-sass": "^1.0.0",
    "grunt-contrib-uglify": "^1.0.1",
    "grunt-contrib-watch": "^1.0.0",
    "grunt-injector": "^1.0.0",
    "concurrently": "^2.0.0",
    "lite-server": "^2.2.0",
    "typescript": "^1.8.10",
    "typings":"^0.8.1"
  }
}

gruntFile.js

module.exports = function (grunt) {


    grunt.initConfig({
        sass: {                              // Task
            dev: {
                options: {                       // Target options
                    style: 'expanded'
                },
                files: {                         // Dictionary of files
                    'app/src/assets/styles/css/index.css': 'app/assets/styles/scss/*.scss'      // 'destination': 'source'
                }
            },
            build: {
                options: {                       // Target options
                    style: 'compressed'
                },
                files: {                         // Dictionary of files
                    'dest/assets/styles/css/index.css': 'app/assets/styles/scss/*.scss'      // 'destination': 'source'
                }
            }
        },
        copy: {
            build: {
                expand: true,
                cwd: 'app/',
                src: ['index.html', 'assets/scripts/**/*.js', 'assets/styles/css/*.css'],
                dest: 'dest/'
            }
        },
        uglify: {
            build: {
                files: {
                    'dest/assets/js/index.min.js': ['app/assets/js/**/*.js']
                }
            }
        },
        watch: {
            css: {
                files: '**/*.scss',
                tasks: ['sass']
            },
            options: {
                livereload: true
            }
        },
        clean: {
            build: {
                src: ['dest']
            }
        },
        injector: {
            dev: {
                options: {
                    template: 'app/index.html'
                },
                files: {
                    'app/src/index.html': ['app/assets/**/*.js', 'app/assets/**/*.css', '//localhost:35729/livereload.js',
                    './node_modules/core-js/client/shim.min.js','./node_modules/zone.js/dist/zone.js',
                    './node_modules/reflect-metadata/Reflect.js','/node_modules/systemjs/dist/system.src.js',
                    './systemjs.config.js']
                }
            },
            build: {
                options: {
                    template: 'dest/index.html'
                },
                files: {
                    'dest/index.html': ['assets/**/*.js', 'assets/**/*.css']
                }
            }
        },
        connect: {
            server: {
                options: {
                    port: 8000,
                    hostname: '*',
                    livereload: true,
                    base: 'app'
                }
            }
        },
        ts: {
            default: {
                src: ["**/*.ts", "!node_modules/**"]
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-injector');
    grunt.loadNpmTasks("grunt-ts");


    grunt.registerTask('default', ['sass:dev','ts', 'injector:dev', 'connect', 'watch']);
    grunt.registerTask('build', ['clean:build', 'sass:build', 'copy:build', 'injector:build']);

};

系统配置.js

/**
 * System configuration for Angular 2 samples
 * Adjust as necessary for your application needs.
 */
(function(global) {
    // map tells the System loader where to look for things
    var map = {
        'app':                        'app', // 'dist',
        '@angular':                   'node_modules/@angular',
        'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
        'rxjs':                       'node_modules/rxjs'
    };
    // packages tells the System loader how to load when no filename and/or no extension
    var packages = {
        'app':                        { main: 'main.js',  defaultExtension: 'js' },
        'rxjs':                       { defaultExtension: 'js' },
        'angular2-in-memory-web-api': { defaultExtension: 'js' }
    };
    var ngPackageNames = [
        'common',
        'compiler',
        'core',
        'http',
        'platform-browser',
        'platform-browser-dynamic',
        'router',
        'router-deprecated',
        'upgrade'
    ];
    // Add package entries for angular packages
    ngPackageNames.forEach(function(pkgName) {
        packages['@angular/'+pkgName] = { main: pkgName + '.umd.js', defaultExtension: 'js' };
    });
    var config = {
        map: map,
        packages: packages
    }
    System.config(config);
})(this);
4

0 回答 0