question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not working correctly with Watchify

See original GitHub issue

After modifying a build for ionic2 to include gulp-inline-ng2-template i stumble upon a strange bug case, the transform with ng2TemplateParser isn’t applied if browserify/watchify/gulpWatch is used.

I’m not sure from where the problem come from so i post it to your knowledge.

var gulp = require('gulp'),
    gulpWatch = require('gulp-watch'),
    browserify = require('browserify'),
    watchify = require('watchify'),
    tsify = require('tsify'),
    pretty = require('prettysize'),
    merge = require('lodash.merge'),
    source = require('vinyl-source-stream'),
    buffer = require('vinyl-buffer'),
    sourcemaps = require('gulp-sourcemaps'),
    uglify = require('gulp-uglify'),
    stream = require('stream'),
    ng2TemplateParser = require('gulp-inline-ng2-template/parser')
    through = require('through2');

var defaultOptions = {
  watch: false,
  src: ['./app/app.ts', './typings/index.d.ts'],
  outputPath: 'www/build/js/',
  outputFile: 'app.bundle.js',
  minify: false,
  browserifyOptions: {
    cache: {},
    packageCache: {},
    debug: true,
    base: '/app',
    useRelativePaths: true,
    supportNonExistentFiles: false
  },
  watchifyOptions: {
    verbose: true
  },
  tsifyOptions: {},
  uglifyOptions: {},
  onError: function(err){
    console.error(err.toString());
    this.emit('end');
  },
  onLog: function(log){
    console.log((log = log.split(' '), log[0] = pretty(log[0]), log.join(' ')));
  }
}

module.exports = function(options) {
  options = merge(defaultOptions, options);

  var b = browserify(options.src, options.browserifyOptions)
    .plugin(tsify, options.tsifyOptions)
    .transform(function(file) {
      return through(function (buf, enc, next) {
        ng2TemplateParser({contents: buf, path: file}, options.browserifyOptions)((err, result) => {
          this.push(result);
          process.nextTick(next);
        });
      });
    });

  if (options.watch) {
    watchify(b, options.watchifyOptions);
    b.on('update', bundle);
    b.on('log', options.onLog);
    gulpWatch('app/**/*.html', bundle);
  }

  return bundle();

  function bundle() {
    return b.bundle()
      .on('error', options.onError)
      .pipe(source(options.outputFile))
      .pipe(buffer())
      .pipe(gulp.dest(options.outputPath));
  }
}

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ludohenincommented, Aug 9, 2016

Can we close ?

0reactions
daKuleMunecommented, Jun 22, 2017

Sure although if I fork this project, I have noticed that small scale this project is fine, but once you have a decent project size the builds can take 40+ seconds and 10 seconds to do a single file update. So I would like to see what I can do to optimize the build time. Doing manual copies of the file contents only added a second to the full build time, so there is something used here that is not scaling very well, but that is a different issue, so I will see about making a bug for that and implementing both in a fork.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Watchify events are not firing · Issue #312 - GitHub
Hi, For severals files in my project, watchify is not working. ... Watchify events are not firing #312 ... And now It works...
Read more >
The term 'watchify' is not recognized as the name of a cmdlet ...
I have tried the following command npm install react browserify watchify 6to5ify --save-dev. and then i tried this watchify -t 6to5ify .
Read more >
@cypress/browserify-preprocessor - npm
Cypress preprocessor for bundling JavaScript via browserify. ... Otherwise, file watching would not function correctly.
Read more >
[Updated] Watchify app not working / wont load / black screen ...
Do you have Watchify app problems? We have instructions to fix the not working issue, loading problems or the common black screen issue...
Read more >
Browserify
Browserify lets you require('modules') in the browser by bundling up all of your dependencies. ... nextTick(), __dirname, and __filename node-isms work ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found