Gulp .
gulpfile.babel.js:
import fs from 'fs';
const pkg = JSON.parse(fs.readFileSync('./package.json'));
import gulp from 'gulp';
import addSrc from 'gulp-add-src';
import concat from 'gulp-concat';
import sourcemaps from 'gulp-sourcemaps';
import uglify from 'gulp-uglify-es';
import babelify from 'babelify';
import browserify from 'browserify';
import buffer from 'vinyl-buffer';
import source from 'vinyl-source-stream';
:
export function scripts() {
const src = pkg.settings.src.scripts;
const bundler = browserify({
entries: src,
debug: true,
transform: [babelify]
});
const outputPath = path.join(__dirname, pkg.settings.out.assets);
const assets = [
'./node_modules/...'
]
return bundler.bundle()
.pipe(source(src))
.pipe(buffer())
.on('error', function(err) { console.error(err); this.emit('end'); })
.pipe(addSrc.prepend(assets))
.pipe(sourcemaps.init())
.pipe(concat(pkg.name + '-' + pkg.version + '.js'))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest(outputPath));
}
.babelrc :
{
"presets": ["env"]
}
, " " " ", .
Also note that I consider the presence of only two different “types” of js modules: my modules imported into the main src file that I give to the browser; and all the external modules and dependencies that I control with NPM and specify here in the array assets.
source
share