问题:
直接concat 那些 js 不行
解决:
html 中改为引用
1 2 |
<script src="dist/es6-shim.min.js" ></script> <script src="dist/angular2.min.js" ></script> |
Gruntfile.js:
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
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