Skip to main content

Using ES6 with gulp

·1 min

For, we’re using gulp as our build system instead of hugo (which is what this site uses), because it allows us to take advantage of the latest goodness available through npm. I really wanted to use ES6 for this project, but I found it a little tricky to find the best way to get minified JS with ES6. The important thing here is that we’re using rollup to both process the ES6 code and minify it using terser. I tried using babelify and uglify, but I ran into trouble with gulp 4’s async task execution model. I kept getting the dreaded “Did you forget to signal async completion?” error. I finally tracked it down to a problem with uglify.

To help whoever comes along, here’s the most important part:


import babel from 'rollup-plugin-babel'
import commonjs from '@rollup/plugin-commonjs'
import eslint from 'gulp-eslint'
import resolve from '@rollup/plugin-node-resolve'
import rollup from 'gulp-better-rollup'
import { terser } from 'rollup-plugin-terser'
import sourcemaps from 'gulp-sourcemaps'

export function scripts () {
  return gulp.src('app/scripts/app.js')
        plugins: [
          resolve({ preferBuiltins: true, mainFields: ['browser'] }),
      { format: 'umd' }))

To see the rest of the config, pop over to github.