I have a buildchain set up in Gulp, but whenever I run the gulp command it only uses one of the two entry points I provide. I am trying to combine the two methods from here:
https://fettblog.eu/gulp-browserify-multiple-bundles/
and here:
https://gist.github.com/frasaleksander/4f7b08b9e0e5cea03919a43372c53d4e
/var/www/website/gulpfile.js
//////////////
// IMPORTS //
/////////////
//Gulp Dependencies
var gulp = require('gulp');
var glob = require('glob');
var es = require('event-stream');
var log = require('fancy-log');
var rename = require('gulp-rename')
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
//JS Dependencies
var tsify = require('tsify');
var watchify = require('watchify');
var browserify = require('browserify');
var uglify = require('gulp-uglify-es').default;
/////////////
// CONFIG //
////////////
var babelconfig = {
presets: ['@babel/preset-env'],
extensions: ['.ts']
}
var tsconfig = {
"moduleResolution": "node",
"target": "es2015",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"lib": [
"DOM",
"ES2015",
"ES2015.Iterable"
]
}
//////////////////
// JAVA SCRIPT //
/////////////////
//JS entry points
var mains = glob.sync('src/js/**/*-main.ts');
mains.forEach(val => {
console.log("main: " + val);
})
//Watchify Object
var watchJS = watchify(browserify({
basedir: '.',
debug: true,
entries: mains,
cache: {},
packageCahce: {}
})).plugin(tsify, tsconfig);
///////////////
// DEFAULTS //
//////////////
gulp.task('default', () => {
var tasks = mains.map(function (entry) {
watchJS.entries = [entry];
return watchJS
.transform('babelify', babelconfig)
.bundle()
.pipe(source(entry))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(rename(function (opt) {
console.log("dirname: " + opt.dirname);
console.log("basename: " + opt.basename);
opt.basename = opt.basename.replace('-main', '');
opt.dirname = opt.dirname.replace('src\/js\/', '');
opt.extname = '.min.js';
}))
.pipe(sourcemaps.write('./'))
.on('end', () => {
console.log("write sourcemapse: " + entry);
})
.pipe(gulp.dest('dist/js/'))
});
return es.merge.apply(null, tasks);
});
//Same as the above, but not a callback function so it can be called below
function js() {
var tasks = mains.map(function (entry) {
watchJS.entries = [entry];
console.log('starting ' + watchJS.entries);
return watchJS
.transform('babelify', babelconfig)
.bundle()
.pipe(source(entry))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(rename(function (opt) {
opt.basename = opt.basename.replace('-main', '');
opt.dirname = opt.dirname.replace('src\/js\/', '');
opt.extname = '.min.js';
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('dist/js/'))
});
}
watchJS.on('update', js);
watchJS.on('log', log);
And here is the output after running gulp:
main: src/js/projects/tesseract/tesseract-main.ts
main: src/js/writings/dead-battery-main.ts
[10:03:35] Using gulpfile /var/www/website/gulpfile.js
[10:03:35] Starting 'default'...
[10:03:42] 3817638 bytes written (3.15 seconds)
dirname: src/js/writings
basename: dead-battery-main
write sourcemapse: src/js/writings/dead-battery-main.ts
As you can see both of the entry points I would like to compile are in the mains array however only one ever finishes. The weirdest part is is I take out the babelify transform both compilations finish. If I'm understanding things correctly without the babelify my JS won't be able to function on nearly as many browsers, otherwise I would just take it out.
My overall goal is to have a build chain that globs all the .*-main.ts files as entry points in src/js/ and spits them out as es5/bundled/minified files in their respective dist/js directories. I would also be more than happy to throw all this out the window and start from scratch is someone can link a guide that sheds some like on a Typescript->Babel->Browserify->Uglify buildchain. Thanks.