AllenYuan

build - browserify - fin

Apr 22nd, 2020
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // views task: bundle all html templates into a templatecache (a big blob of html in a js file),
  2. // rename it app.templates.js and move it to ./src/js/config/
  3. gulp.task('views', function () {
  4.   return (
  5.     gulp
  6.       // take all the html templates
  7.       .src(viewFiles)
  8.       // pipe them into a templatecache file
  9.       .pipe(
  10.         templateCache({
  11.           standalone: true,
  12.         })
  13.       )
  14.       // if there are errors, print them
  15.       .on('error', interceptErrors)
  16.       // rename the file app.templates.js
  17.       .pipe(rename('app.templates.js'))
  18.       // move it to ./src/js/config/
  19.       .pipe(gulp.dest('./src/js/config/'))
  20.   );
  21. });
  22.  
  23. // browserify task: run views to get the HTML into ./src/js/config, then bundle up all the
  24. // JS, JS dependencies, and HTML into a big file of ES5 Javascript called main.js in the ./build/ folder
  25. gulp.task('browserify', ['views'], function () {
  26.   return (
  27.     // bundle up all the JS through the root file app.js
  28.     browserify('./src/js/app.js')
  29.       // transpile to es5
  30.       .transform(babelify, {presets: ['es2015']})
  31.       // inject dependencies
  32.       .transform(ngAnnotate)
  33.       // bundle the js
  34.       .bundle()
  35.       // error => use interceptErrors passthrough
  36.       .on('error', interceptErrors)
  37.       // output to main.js
  38.       .pipe(source('main.js'))
  39.       // move main.js to ./build
  40.       .pipe(gulp.dest('./build/'))
  41.   );
  42. });
Advertisement
Add Comment
Please, Sign In to add comment