Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. 'use strict';
  2.  
  3. var browserify = require('browserify');
  4. var watchify = require('watchify');
  5. var bs = require('browser-sync');
  6. var ws = require('fs').createWriteStream;
  7. var to5ify = require('6to5ify');
  8.  
  9. var outDir = './public/';
  10. var config = {
  11. browserify: {
  12. entryFile: './src/index.js',
  13. outFile: outDir + 'bundle.js',
  14. args: {
  15. cache: {}, //
  16. packageCache: {}, // these three are required for watchify
  17. fullPaths: true, //
  18. debug: true
  19. }
  20. },
  21. browserSync: {
  22. server: {
  23. baseDir: outDir
  24. }
  25. }
  26. };
  27.  
  28. var tasks = {
  29. watch: function() {
  30. var b = browserify(config.browserify.args)
  31. .transform(to5ify.configure({
  32. experimental: true,
  33. modules: 'commonInterop'
  34. }))
  35. .add('6to5/polyfill')
  36. .require(config.browserify.entryFile, { entry: true });
  37.  
  38. var w = watchify(b);
  39.  
  40. var rebundle = function() {
  41. w.bundle()
  42. .on('error', function(err) {
  43. var msg = '[Browserify] ERROR: ' + err.message;
  44. if(bs.active) {
  45. // set a timeout, because the initial 'BrowserSync connected'
  46. // message helpfully squashes any other notifications on reload
  47. setTimeout(function() {
  48. bs.notify(msg, 10000);
  49. }, 1000);
  50. }
  51. console.error(msg);
  52. })
  53. .on('end', function() {
  54. if(bs.active) {
  55. bs.reload();
  56. }
  57. })
  58. .pipe(ws(config.browserify.outFile));
  59. };
  60.  
  61. w.on('update', rebundle);
  62. w.on('log', console.log);
  63.  
  64. rebundle();
  65. },
  66. serve: function() {
  67. bs(config.browserSync);
  68. tasks.watch();
  69. }
  70. };
  71.  
  72. var task = process.argv.slice(2)[0];
  73. tasks[task]();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement