How to create an angular 2 build folder when using systemjs.config.js

喜欢而已 提交于 2019-11-29 03:50:53

Try this:

//in the gulpfile.js
gulp.task("angular", () => {
    return gulp.src([ '@angular/**','rxjs/**']).pipe(gulp.dest("./dist"));    
});

// in the config.js
var map = {
   'app':                        'dist', //I guess that the problem was here
   'rxjs':                       'dist/rxjs',
   'angular2-in-memory-web-api': 'dist/angular2-in-memory-web-api',
   '@angular':                   'dist/@angular'
};
Ankit Singh

Your gulp-task vendor-bundle suggests that you want a bundle of the dependencies used in your app. If you can use system-js-builder, it'll be very easy.

  • It will be much smaller than the whole bundle of angular or rxjs

Just run this


It'll include angular and rxjs dependencies

var gulp = require('gulp'),
  Builder = require('systemjs-builder');


gulp.task('bundle-dependencies', function() {
  // optional constructor options
  // sets the baseURL and loads the configuration file
  var builder = new Builder('', 'config.js'); // config.js is the name of systemjs config file

  return builder
    .bundle('app/boot.js - [app/**/*.js]', 'path/to/put/dependencies.bundle.js', { minify: true})
    .then(function() {
      console.log('Build complete');
    })
    .catch(function(err) {
      console.log('Build error');
      console.log(err);
    });
});

for a complete guide see my another answer Compile Angular 2 node_modules files into one file.

Note: path/to/put/ is the path where you want to export the bundle.


If you want files of the dependencies, I'm sorry. But I'd suggest to create a bundle intead of having seperate files.

Here you go,

gulpfile

   gulp.task('vendor', function () {
      var includeLibrary = [
          "./node_modules/systemjs/dist/system.src.js",
          "./node_modules/es6-shim/es6-shim.min.js",
          "./node_modules/zone.js/dist/zone.js",
          "./node_modules/reflect-metadata/Reflect.js",        
          "./node_modules/rxjs/**/*.js",
          "./node_modules/angular2-in-memory-web-api/**/*.js",
          "./node_modules/@angular/**/*.js",
          "./node_modules/crypto-js/crypto-js.js"
      ]
      return gulp.src(includeLibrary, { base: './node_modules/' })
       .pipe(gulp.dest('dist/lib/'));
   });

system.config

   let map: any = {
     "app": "",
     "rxjs": "lib/rxjs",
     "angular2-in-memory-web-api": "lib/angular2-in-memory-web-api",
     "@angular": "lib/@angular",
     "reflect-metadata": "lib/Reflect.js",
     "crypto": "lib/crypto-js/crypto-js.js"
   };

index.html

     <head>
       <base href="/dist/" />
       <title>App Title</title>
       <meta charset="UTF-8">
       <meta name="viewport" content="width=device-width, initial-scale=1">

       <!-- 1. Load libraries -->
       <!-- Polyfill(s) for older browsers -->
       <script src="lib/es6-shim/es6-shim.min.js"></script>

       <script src="lib/zone.js/dist/zone.js"></script>
       <script src="lib/reflect-metadata/Reflect.js"></script>
       <script src="lib/systemjs/dist/system.src.js"></script>
       <!-- 2. Configure SystemJS -->
       <script src="systemjs.config.js"></script>

       <script>

        System.import('app').catch(function(err){ console.error(err);  });
       </script>
    </head>

above assumes your gulpfile and node_modules are on same level.

Hope this helps!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!