2016年3月25日 | Leave a comment 问题: 直接concat 那些 js 不行 解决: html 中改为引用 <script src="dist/es6-shim.min.js" ></script> <script src="dist/angular2.min.js" ></script> 12 <script src="dist/es6-shim.min.js" ></script> <script src="dist/angular2.min.js" ></script> Gruntfile.js: JavaScript var typescriptFiles = ["app/**/*.ts", "!app/typings/**/*.*"]; module.exports = function(grunt) { grunt.loadNpmTasks("grunt-ts"); grunt.loadNpmTasks("grunt-contrib-concat"); grunt.loadNpmTasks("grunt-contrib-uglify"); grunt.loadNpmTasks("grunt-contrib-clean"); grunt.loadNpmTasks("grunt-contrib-watch"); grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks("grunt-concat-sourcemap"); grunt.loadNpmTasks('grunt-newer'); grunt.initConfig({ pkg: grunt.file.readJSON("package.json"), ts: { app: { src: typescriptFiles, dest: 'dist/app', options: { module: 'system', moduleResolution: 'node', target: 'es5', experimentalDecorators: true, emitDecoratorMetadata: true, noImplicitAny: false } } }, watch: { options: { interval: 1000 }, ts: { files: typescriptFiles, tasks: ["newer:ts:app"] } }, copy: { main: { files: [{ expand: false, flatten: true, src: ["node_modules/es6-shim/es6-shim.min.js"], dest: 'dist/es6-shim.min.js', filter: 'isFile' }], }, }, concat: { angular2: { options:{ sourceMap: false, stripBanners: true }, src: [ "node_modules/systemjs/dist/system-polyfills.js", "node_modules/angular2/bundles/angular2-polyfills.min.js", "node_modules/systemjs/dist/system.src.js", "node_modules/rxjs/bundles/Rx.min.js", "node_modules/angular2/bundles/angular2.min.js", "node_modules/angular2/bundles/router.dev.js", "node_modules/jquery/dist/jquery.min.js", "node_modules/js-cookie/src/js.cookie.js", "node_modules/bootstrap/dist/js/bootstrap.js", ], dest: "dist/angular2.js" } }, uglify: { options: { mangle: false, sourceMap: true }, dist: { files: { "dist/angular2.min.js": ["dist/angular2.js"] } } } }); return grunt.registerTask("default", ["ts", "copy", "concat", "uglify"]); }; 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 var typescriptFiles = ["app/**/*.ts", "!app/typings/**/*.*"]; module.exports = function(grunt) { grunt.loadNpmTasks("grunt-ts"); grunt.loadNpmTasks("grunt-contrib-concat"); grunt.loadNpmTasks("grunt-contrib-uglify"); grunt.loadNpmTasks("grunt-contrib-clean"); grunt.loadNpmTasks("grunt-contrib-watch"); grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks("grunt-concat-sourcemap"); grunt.loadNpmTasks('grunt-newer'); grunt.initConfig({ pkg: grunt.file.readJSON("package.json"), ts: { app: { src: typescriptFiles, dest: 'dist/app', options: { module: 'system', moduleResolution: 'node', target: 'es5', experimentalDecorators: true, emitDecoratorMetadata: true, noImplicitAny: false } } }, watch: { options: { interval: 1000 }, ts: { files: typescriptFiles, tasks: ["newer:ts:app"] } }, copy: { main: { files: [{ expand: false, flatten: true, src: ["node_modules/es6-shim/es6-shim.min.js"], dest: 'dist/es6-shim.min.js', filter: 'isFile' }], }, }, concat: { angular2: { options:{ sourceMap: false, stripBanners: true }, src: [ "node_modules/systemjs/dist/system-polyfills.js", "node_modules/angular2/bundles/angular2-polyfills.min.js", "node_modules/systemjs/dist/system.src.js", "node_modules/rxjs/bundles/Rx.min.js", "node_modules/angular2/bundles/angular2.min.js", "node_modules/angular2/bundles/router.dev.js", "node_modules/jquery/dist/jquery.min.js", "node_modules/js-cookie/src/js.cookie.js", "node_modules/bootstrap/dist/js/bootstrap.js", ], dest: "dist/angular2.js" } }, uglify: { options: { mangle: false, sourceMap: true }, dist: { files: { "dist/angular2.min.js": ["dist/angular2.js"] } } } }); return grunt.registerTask("default", ["ts", "copy", "concat", "uglify"]);}; 参考: https://github.com/lokeshpahal/angular2-typescript-grunt