Skip to content

Instantly share code, notes, and snippets.

@c-johnson
Created December 13, 2017 20:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c-johnson/b66d376b686c16efeb26484e89279558 to your computer and use it in GitHub Desktop.
Save c-johnson/b66d376b686c16efeb26484e89279558 to your computer and use it in GitHub Desktop.
Simple Gulp setup with Rollup, Babel, JSX, sourcemaps, and livereload
{
"presets": [
["@babel/preset-env", {
"modules": false
}]
],
"plugins": [["@babel/plugin-transform-react-jsx"]]
}
var gulp = require('gulp');
var cssimport = require('gulp-cssimport');
var cssnano = require('gulp-cssnano');
var rollup = require('rollup');
var babel = require('rollup-plugin-babel');
var resolve = require('rollup-plugin-node-resolve');
var commonjs = require('rollup-plugin-commonjs');
var replace = require('rollup-plugin-replace');
var serve = require('gulp-webserver');
gulp.task('bundle-css', function() {
gulp
.src('src/index.css')
.pipe(cssimport())
.pipe(cssnano())
.pipe(gulp.dest('./dist/css/'));
});
gulp.task('bundle-js', function() {
return rollup.rollup({
input: './src/index.js',
plugins: [
babel({
exclude: 'node_modules/**'
}),
commonjs({
namedExports: {
'node_modules/react/index.js': [ 'Component' ]
}
}),
replace({
'process.env.NODE_ENV': JSON.stringify('production')
}),
resolve()
]
}).then(bundle => {
return bundle.write({
file: './dist/js/index.js',
format: 'umd',
name: 'index',
sourcemap: "inline"
});
});
});
gulp.task('server', function () {
gulp.src('.')
.pipe(serve({
livereload: true,
directoryListing: true,
open: true
}));
});
gulp.task('watch', function() {
gulp.watch('src/**/*.js', ['bundle-js']);
gulp.watch('src/**/*.css', ['bundle-css']);
})
gulp.task('default', [ 'bundle-js', 'bundle-css' ]);
gulp.task('serve', ['server', 'watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment