-
-
Save naturalkei/d3db7855e0aa225eb64da9ab5e734ebc to your computer and use it in GitHub Desktop.
Rollup, Gulp, and Babel (ES6)
This file contains 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
// Gulp | |
import gulp from 'gulp'; | |
import plumber from 'gulp-plumber'; | |
import file from 'gulp-file'; | |
import filter from 'gulp-filter'; | |
import rename from 'gulp-rename'; | |
import sourcemaps from 'gulp-sourcemaps'; | |
import uglify from 'gulp-uglify'; | |
// Rollup | |
import { rollup } from 'rollup'; | |
import babel from 'rollup-plugin-babel'; | |
import json from 'rollup-plugin-json'; | |
// Misc | |
import runSequence from 'run-sequence'; | |
import {name} from '../package.json'; | |
// Const | |
const srcPath = 'src/'; | |
const buildPath = 'dist/'; | |
function _generate(bundle){ | |
return bundle.generate({ | |
format: 'umd', | |
moduleName: 'myModule', | |
sourceMap: true | |
}); | |
} | |
function bundle(opts) { | |
return rollup({ | |
entry: srcPath + name + '.js', | |
plugins: [ | |
json(), | |
babel({ | |
presets: [ | |
["es2015", { | |
"modules": false | |
} | |
] | |
], | |
sourceMaps: true, | |
babelrc: false, | |
exclude: 'node_modules/**' | |
}) | |
] | |
}).then(bundle => { | |
return _generate(bundle); | |
}).then(gen => { | |
gen.code += '\n//# sourceMappingURL=' + gen.map.toUrl(); | |
return gen; | |
}); | |
} | |
gulp.task('build-lib', ['lint-src'], function(){ | |
return bundle().then(gen => { | |
return file(name + '.js', gen.code, {src: true}) | |
.pipe(plumber()) | |
.pipe(sourcemaps.init({loadMaps: true})) | |
.pipe(sourcemaps.write('./')) | |
.pipe(gulp.dest(buildPath)) | |
.pipe(filter(['*', '!**/*.js.map'])) | |
.pipe(rename(name + '.min.js')) | |
.pipe(sourcemaps.init({loadMaps: true})) | |
.pipe(uglify({ | |
preserveComments: 'license' | |
})) | |
.pipe(sourcemaps.write('./')) | |
.pipe(gulp.dest(buildPath)); | |
}); | |
}); | |
gulp.task('build', function(done) { | |
runSequence('build-lib', done); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment