Created
August 20, 2017 17:59
-
-
Save searbe/fa221ab6c2ae86d451c60c0cb12f9273 to your computer and use it in GitHub Desktop.
gulp & rollup without breaking gulp streams
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gulp = require('gulp'); | |
const uglify = require('gulp-uglify'); | |
const sourcemaps = require('gulp-sourcemaps'); | |
const buble = require('rollup-plugin-buble'); | |
const commonjs = require('rollup-plugin-commonjs'); | |
const nodeResolve = require('rollup-plugin-node-resolve'); | |
const rollup = require('rollup-stream'); | |
const source = require('vinyl-source-stream'); | |
const buffer = require('vinyl-buffer'); | |
let rollupOptions = { | |
entry: './src/main.js', | |
sourceMap: true, | |
plugins: [ | |
// Rolls up NodeJS modules | |
nodeResolve({ | |
jsnext: true, | |
main: true | |
}), | |
// "Convert CommonJS modules to ES6, so they can be included in a Rollup bundle" | |
commonjs({ | |
include: 'node_modules/**', | |
sourceMap: true | |
}), | |
// Lightweight babel alternative | |
buble() | |
], | |
external: [ | |
// Do not roll-up these imports | |
'jquery' | |
], | |
globals: { | |
// When jquery is imported, name is jQuery in generated code | |
jquery: 'jQuery' | |
}, | |
// Instantly invoked function extraletterontheend | |
format: 'iife', | |
// Don't trim unused code (delete that code yourself.) | |
treeshake: false | |
}; | |
gulp.task('build', function() { | |
return rollup(rollupOptions) | |
.pipe(source('main.js', './src')) | |
.pipe(buffer()) | |
.pipe(sourcemaps.init({ loadMaps: true })) | |
.pipe(uglify()) | |
.pipe(sourcemaps.write('.')) | |
.pipe(gulp.dest('./dist')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment