Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. var gulp = require('gulp');
  2. var sourcemaps = require('gulp-sourcemaps');
  3. var concat = require('gulp-concat');
  4. var typescript = require('gulp-typescript');
  5. var systemjsBuilder = require('systemjs-builder');
  6.  
  7. // Compile TypeScript app to JS
  8. gulp.task('compile:ts', function () {
  9. return gulp
  10. .src([
  11. "src/**/*.ts",
  12. "typings/*.d.ts"
  13. ])
  14. .pipe(sourcemaps.init())
  15. .pipe(typescript({
  16. "module": "system",
  17. "moduleResolution": "node",
  18. "outDir": "app",
  19. "target": "ES5"
  20. }))
  21. .pipe(sourcemaps.write('.'))
  22. .pipe(gulp.dest('app'));
  23. });
  24.  
  25. // Generate systemjs-based bundle (app/app.js)
  26. gulp.task('bundle:app', function() {
  27. var builder = new systemjsBuilder('public', './system.config.js');
  28. return builder.buildStatic('app', 'app/app.js');
  29. });
  30.  
  31. // Copy and bundle dependencies into one file (vendor/vendors.js)
  32. // system.config.js can also bundled for convenience
  33. gulp.task('bundle:vendor', function () {
  34. return gulp.src([
  35. 'node_modules/jquery/dist/jquery.min.js',
  36. 'node_modules/bootstrap/dist/js/bootstrap.min.js',
  37. 'node_modules/es6-shim/es6-shim.min.js',
  38. 'node_modules/es6-promise/dist/es6-promise.min.js',
  39. 'node_modules/zone.js/dist/zone.js',
  40. 'node_modules/reflect-metadata/Reflect.js',
  41. 'node_modules/systemjs/dist/system-polyfills.js',
  42. 'node_modules/systemjs/dist/system.src.js',
  43. ])
  44. .pipe(concat('vendors.js'))
  45. .pipe(gulp.dest('vendor'));
  46. });
  47.  
  48. // Copy dependencies loaded through SystemJS into dir from node_modules
  49. gulp.task('copy:vendor', function () {
  50. gulp.src(['node_modules/rxjs/**/*'])
  51. .pipe(gulp.dest('public/lib/js/rxjs'));
  52.  
  53. gulp.src(['node_modules/angular2-in-memory-web-api/**/*'])
  54. .pipe(gulp.dest('public/lib/js/angular2-in-memory-web-api'));
  55.  
  56. return gulp.src(['node_modules/@angular/**/*'])
  57. .pipe(gulp.dest('public/lib/js/@angular'));
  58. });
  59.  
  60. gulp.task('vendor', ['bundle:vendor', 'copy:vendor']);
  61. gulp.task('app', ['compile:ts', 'bundle:app']);
  62.  
  63. // Bundle dependencies and app into one file (app.bundle.js)
  64. gulp.task('bundle', ['vendor', 'app'], function () {
  65. return gulp.src([
  66. 'app/app.js',
  67. 'vendor/vendors.js'
  68. ])
  69. .pipe(concat('app.bundle.js'))
  70. .pipe(uglify())
  71. .pipe(gulp.dest('./app'));
  72. });
  73.  
  74. gulp.task('default', ['bundle']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement