-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not working correctly with Watchify #55
Comments
I have a working and dirty solution for ionic2. Here is my code : function templateInliner(file) {
return through(function (buf, enc, next) {
ng2TemplateParser({ contents: buf, path: file }, inlinerOptions)((err, result) => {
this.push(result);
process.nextTick(next);
});
});
}
var buildBrowserify = function (options) {
options = merge(defaultOptions, options);
var b = browserify(options.src, options.browserifyOptions)
.plugin(tsify, options.tsifyOptions);
if (options.watch) {
b = watchify(b, options.watchifyOptions);
b.on('update', bundle);
b.on('log', options.onLog);
}
b = b.transform(templateInliner);
return bundle();
function bundle() {
var debug = options.browserifyOptions.debug;
return b
.bundle()
.on('error', options.onError)
.pipe(source(options.outputFile))
.pipe(buffer())
.pipe(debug ? sourcemaps.init({ loadMaps: true }) : noop())
.pipe(options.minify ? uglify(options.uglifyOptions) : noop())
.pipe(debug ? sourcemaps.write('./', { includeContent: true, sourceRoot: '../../../' }) : noop())
.pipe(gulp.dest(options.outputPath));
}
function noop() {
return new stream.PassThrough({ objectMode: true });
}
} hope this helps |
It look a lot like my last version I posted on the forum ionic2 but thanks :D |
Can we close ? |
Surely this should still be open as the issue still persists (templates not being watched)? |
Here is my solution to trigger rebuilds when indirect dependencies change: // ng2inlinetransform.js
var ng2TemplateParser = require('gulp-inline-ng2-template/parser');
var through = require('through2');
module.exports = function (file) {
return through(function (buf, enc, next) {
var stream = this
var fileProcessorFn = function (path, ext, file, callback) {
try {
// emitting the file for watchify to pick it up as dependency and triggering rebuild on change
// https://github.com/substack/watchify/issues/215
stream.emit('file', path)
callback(null, file);
}
catch (err) {
callback(err);
}
}
// rest is done as documented
// https://github.com/ludohenin/gulp-inline-ng2-template#browserify-transform-example
var options = {
target: 'es6',
useRelativePaths: true,
templateProcessor: fileProcessorFn,
styleProcessor: fileProcessorFn
};
ng2TemplateParser({contents: buf, path: file}, options)((err, result) => {
this.push(result);
process.nextTick(next);
});
});
} |
This should not have been close before being at least explained in the README.md. The fact that I found this was dump luck. Colorfulstan answer is by far the most descriptive, as it can easily be applied to the style method as well. |
Would you please make a PR for that ? |
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. |
After modifying a build for ionic2 to include
gulp-inline-ng2-template
i stumble upon a strange bug case, the transform withng2TemplateParser
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.
The text was updated successfully, but these errors were encountered: