esbuild is a very fast web bundler. This repo defines a skeletal web/js project including linting, testing, local running, and bundling using esbuild.
It includes the following features:
- Bundling the projects JS code into a single
app.jsfile, using esbuild bundler. - Run a server to serve the bundled code using serve.
- Run unit tests using web-test-runner and chai.
- Run lint using ESLint.
- The root of the project contains these files
eslint.config.js: ES Lint customized rules.gitignore: List of files to be ignored by gitpackage.json,package-lock.json: NPM package definition.README.md: This file.web-test-runner.config.mjs: web-test-runner configuration using Puppeteer headless.
scripts/directory: Contains build scripts.src/directory: Contains the application's source, including js, html, css, images, ...target/directory: Will be generated after the first build. Contains build-generated files and directories:coverage/directory: Will be generated after the first test run. Contains test coverage reportdist/directory: Contains the distribution files and source map
Note: The code included in src is for demo purposes. You can change or remove it as you see fit.
Please look at package.json scripts section for a quick look at the supported commands.
After you clone this repo to your local machine:
cd esbuild-project-starter
npm ciThe above will download the node_modules dependencies of this project without modifying package-lock.json.
Remove build artifacts. Will remove the target/ directory.
npm run cleanCreate bundle in target/dist/
npm run buildCreate a minified bundle in target/dist/
npm run build:prodnpm run serverThe root directory of the server will be the target/ directory. It will recreate the bundle for every *.html file request.
Note that esbuild is a very fast bundler, so re-bundling should not slow down you page requests.
Test files names should follow the pattern *.test.js. Look at src/utils/test/ for examples.
Run all test. Will generate a coverage report in target/coverage/lcov-report/index.html
npm run testRun test watcher:
npm run test:watchnpm run lint- esbuild: https://esbuild.github.io/
- Web Test Runner: https://modern-web.dev/docs/test-runner/overview/
- Chai: https://www.chaijs.com/api/bdd/
- ESLint: https://eslint.org/docs/rules/
- serve: https://www.npmjs.com/package/serve