This repo demonstrates my current opinions on how to build an Express webapp using Gulp 4. Currently it is rather complex; expect it to get simpler as I extract reusable packages.
Features:
- Compiles ES2015 to backwards-compatible ES3. Sourcemaps included!
- Uses Browserify to pack the tree of
require
d files into a single, minified JS file that can be run in a browser. - Runs tests with Jasmine.
- ESLint enforces Standard JS style.
- Dependency injection with Yavanna makes unit-testing a breeze, and saves you from having to change your
require
s when you want to move or rename a source file. - The
gulp watch
task rebuilds the app and runs the tests and linter on every file change for the tightest possible feedback loop.
If you want to use this repo as a template for your own project, you can clone the latest version and reinitialize the repository:
git clone --depth=1 https://github.com/benchristel/gulp-express-example.git myproject
cd myproject
mv .git /tmp # because `rm -rf` is for crazy people
git init
brew install node
The -g
flag installs the CLI globally, making the gulp
executable available on your PATH
.
npm install -g gulpjs/gulp-cli
npm install # must be run inside your project directory
gulp watch --silent # suppress gulp output cruft
- An option to build a production version of the app with minified browser code (I originally had
uglify
in the normal build pipeline, but it was too slow to use for development) - A version of the build pipeline that works for published NPM packages, or CLI apps.
-
Because of the way tests are currently run, you can't have different server and browser modules with the same name. For example, if you have a
User
class on the server that's a database model, you can't have a separateUser
class for the browser—the dependency injector will complain that you're registering two modules with the same name.Depending on the structure of your team, this constraint on naming may or may not be desirable. It should be possible to run the browser and server tests in separate Jasmine instances so the names don't collide, but I haven't gotten to it yet.