使用systemjs.config.js时如何创建一个角度2的构建文件夹

前端之家收集整理的这篇文章主要介绍了使用systemjs.config.js时如何创建一个角度2的构建文件夹前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用systemjs.config.js时如何创建一个角度2的构建文件

我的应用程序在本地工作正常
我需要帮助我的gulp文件,所以我可以抓住需要的节点模块,并将它们移动到dist文件夹准备好部署.

这是我的gulp文件夹:

  1. const gulp = require('gulp');
  2. const ts = require('gulp-typescript');
  3. const uglify = require('gulp-uglify');
  4. const concat = require('gulp-concat');
  5. var htmlreplace = require('gulp-html-replace');
  6. var addsrc = require('gulp-add-src');
  7. var sass = require('gulp-sass');
  8. var inject = require('gulp-inject');
  9. var del = require('delete');
  10. var minifyCss = require('gulp-minify-css');
  11. var CacheBuster = require('gulp-cachebust');
  12. var cachebust = new CacheBuster();
  13.  
  14. gulp.task('app-bundle',function () {
  15. var tsProject = ts.createProject('tsconfig.json',{
  16. typescript: require('typescript'),outFile: 'app.js'
  17. });
  18.  
  19. var tsResult = gulp.src([
  20. 'node_modules/angular2/typings/browser.d.ts','typings/main/ambient/firebase/firebase.d.ts','app/**/*.ts'
  21. ])
  22. .pipe(ts(tsProject));
  23.  
  24. return tsResult.js.pipe(addsrc.append('config-prod.js'))
  25. .pipe(concat('app.min.js'))
  26. .pipe(uglify())
  27. .pipe(gulp.dest('./dist'));
  28. });
  29.  
  30. gulp.task('vendor-bundle',function() {
  31. gulp.src([
  32. 'node_modules/es6-shim/es6-shim.min.js','node_modules/systemjs/dist/system-polyfills.js','node_modules/angular2/bundles/angular2-polyfills.js','node_modules/systemjs/dist/system.src.js','node_modules/rxjs/bundles/Rx.js','node_modules/angular2/bundles/angular2.dev.js','node_modules/angular2/bundles/http.dev.js'
  33. ])
  34. .pipe(concat('vendors.min.js'))
  35. .pipe(uglify())
  36. .pipe(gulp.dest('./dist'));
  37. });
  38.  
  39. gulp.task('add-styles',function() {
  40. gulp.src([
  41. 'css/animate.css','css/bootstraptheme.css','sass/styles.scss'
  42. ])
  43. .pipe(sass().on('error',sass.logError))
  44. .pipe(concat('styles.min.css'))
  45. .pipe(minifyCss({compatibility: 'ie8'}))
  46. .pipe(cachebust.resources())
  47. .pipe(gulp.dest('dist/'))
  48. });
  49.  
  50. gulp.task('add-images',function() {
  51. gulp.src([
  52. 'images/*.png'
  53. ])
  54. .pipe(gulp.dest('dist/images'))
  55. });
  56.  
  57. gulp.task('add-bits',function() {
  58. gulp.src([
  59. 'favicon*.*','sitemap.xml','robots.txt','firebase.json'
  60. ])
  61. .pipe(gulp.dest('dist/'))
  62. });
  63.  
  64. gulp.task('html-replace',[ 'app-bundle','vendor-bundle','add-styles','add-images','add-bits'],function() {
  65. gulp.src('index.html')
  66. .pipe(htmlreplace({
  67. 'vendor': 'vendors.min.js','app': 'app.min.js'
  68. }))
  69. .pipe(gulp.dest('dist'));
  70. });

这是我目前的dist文件夹的屏幕抓取,可以实时部署.但是缺少所需的节点模块:

这是我的配置文件

  1. (function(global) {
  2.  
  3. // map tells the System loader where to look for things
  4. var map = {
  5. 'app': 'app','rxjs': 'node_modules/rxjs','angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api','@angular': 'node_modules/@angular'
  6. };
  7.  
  8. // packages tells the System loader how to load when no filename and/or no extension
  9. var packages = {
  10. 'app': { main: 'boot.js',defaultExtension: 'js' },'rxjs': { defaultExtension: 'js' },'angular2-in-memory-web-api': { defaultExtension: 'js' },'angular2-google-maps': { defaultExtension: 'js' }
  11. };
  12.  
  13. var packageNames = [
  14. '@angular/common','@angular/compiler','@angular/core','@angular/http','@angular/platform-browser','@angular/platform-browser-dynamic','@angular/router','@angular/router-deprecated','@angular/testing','@angular/upgrade',];
  15.  
  16. // add package entries for angular packages in the form '@angular/common': { main: 'index.js',defaultExtension: 'js' }
  17. packageNames.forEach(function(pkgName) {
  18. packages[pkgName] = { main: 'index.js',defaultExtension: 'js' };
  19. });
  20.  
  21. var config = {
  22. map: map,packages: packages
  23. }
  24.  
  25. // filterSystemConfig - index.html's chance to modify config before we register it.
  26. if (global.filterSystemConfig) { global.filterSystemConfig(config); }
  27.  
  28. System.config(config);
  29.  
  30. })(this);

这些是我认为缺少的节点模块,需要添加到dist文件夹并链接到dist文件夹index.html

  1. var packageNames = [
  2. '@angular/common',];

这是我的索引文件

  1. <html lang="en" prefix="og: http://ogp.me/ns#" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <title>App</title>
  4. <base href="/"></base>
  5.  
  6. <!-- Css libs -->
  7. <link rel="stylesheet" type="text/css" href="/css/animate.css" />
  8. <link rel="stylesheet" type="text/css" href="/css/bootstraptheme.css" />
  9. <link href='https://fonts.googleapis.com/css?family=Lato:400,100,100italic,300italic,300,400italic,700italic,900,700,900italic' rel='stylesheet' type='text/css'>
  10. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
  11.  
  12. <!-- build:css -->
  13. <link rel="stylesheet" href="css/styles.css">
  14. <!-- endbuild -->
  15.  
  16. <!-- Js libs -->
  17. <script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
  18. <script src="https://www.amcharts.com/lib/3/pie.js"></script>
  19. <script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
  20. <script type="text/javascript" src="https://cdn.jsdelivr.net/lodash/4.11.2/lodash.min.js"></script>
  21. <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  22. <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
  23. <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  24.  
  25. <!-- build:vendor -->
  26. <script src="node_modules/es6-shim/es6-shim.min.js"></script>
  27. <script src="node_modules/zone.js/dist/zone.js"></script>
  28. <script src="node_modules/reflect-Metadata/Reflect.js"></script>
  29. <script src="node_modules/systemjs/dist/system.src.js"></script>
  30.  
  31. <script src="node_modules/angular2-google-maps/bundles/angular2-google-maps.js"></script>
  32. <!-- endbuild -->
  33.  
  34. <script src="https://cdn.firebase.com/js/client/2.3.2/firebase.js"></script>
  35.  
  36. <!-- build:app -->
  37. <script src="config.js"></script>
  38. <script>
  39. System.import('app').catch(function(err){ console.error(err); });
  40. </script>
  41. <!-- endbuild -->
  42.  
  43. </head>
  44.  
  45. <body id="container">
  46. <my-app>Loading...</my-app>
  47. </body>
  48. </html>

解决方法

尝试这个:
  1. //in the gulpfile.js
  2. gulp.task("angular",() => {
  3. return gulp.src([ '@angular/**','rxjs/**']).pipe(gulp.dest("./dist"));
  4. });
  5.  
  6. // in the config.js
  7. var map = {
  8. 'app': 'dist',//I guess that the problem was here
  9. 'rxjs': 'dist/rxjs','angular2-in-memory-web-api': 'dist/angular2-in-memory-web-api','@angular': 'dist/@angular'
  10. };

猜你在找的JavaScript相关文章