Created
December 13, 2017 20:09
-
-
Save c-johnson/b66d376b686c16efeb26484e89279558 to your computer and use it in GitHub Desktop.
Simple Gulp setup with Rollup, Babel, JSX, sourcemaps, and livereload
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
Show hidden characters
{ | |
"presets": [ | |
["@babel/preset-env", { | |
"modules": false | |
}] | |
], | |
"plugins": [["@babel/plugin-transform-react-jsx"]] | |
} |
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
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