├── .editorconfig ├── .gitignore ├── .prettierrc ├── license ├── package.json ├── readme.md └── src └── index.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.yml] 12 | indent_style = space 13 | indent_size = 2 14 | 15 | [*.md] 16 | indent_style = space 17 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | yarn.lock 4 | package-lock.json 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "none", 4 | "arrowParens": "avoid", 5 | "printWidth": 90 6 | } 7 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) Antoine Boulanger (https://github.com/ABXlink) 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "esbuild-serve", 3 | "version": "1.0.1", 4 | "description": "Serve with live reload for esbuild.", 5 | "repository": "nativew/esbuild-serve", 6 | "author": "Antoine Boulanger (https://github.com/antoineboulanger)", 7 | "license": "ISC", 8 | "exports": "./src/index.js", 9 | "main": "src/index.js", 10 | "type": "module", 11 | "scripts": { 12 | "format": "prettier --write --ignore-unknown '**/*'" 13 | }, 14 | "dependencies": { 15 | "create-serve": "^1.0.1", 16 | "esbuild": "^0.9.0" 17 | }, 18 | "devDependencies": { 19 | "prettier": "^2.2.1" 20 | }, 21 | "files": [ 22 | "src" 23 | ], 24 | "keywords": [ 25 | "esbuild", 26 | "wrapper", 27 | "plugin", 28 | "serve", 29 | "http", 30 | "server", 31 | "livereload", 32 | "live", 33 | "reload", 34 | "hot", 35 | "refresh" 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # esbuild-serve 4 | 5 | [Serve](https://github.com/nativew/serve) with live reload for [esbuild](https://github.com/evanw/esbuild). 6 | 7 |
8 | 9 | ### Simple esbuild wrapper 10 | 11 | ### Serves your site locally 12 | 13 | ### With live reload 14 | 15 | ### Using esbuild's watch 16 | 17 | ### And an ultralight server 18 | 19 |
20 | 21 | ### Install 22 | 23 | ```zsh 24 | npm install esbuild-serve -D 25 | ``` 26 | 27 |
28 | 29 | ### Use 30 | 31 | `esbuild.config.js` 32 | 33 | ```js 34 | import esbuildServe from 'esbuild-serve'; 35 | 36 | esbuildServe( 37 | { 38 | // esbuild options 39 | }, 40 | { 41 | // serve options (optional) 42 | port: 7000, 43 | root: '.' 44 | } 45 | ); 46 | ``` 47 | 48 | `package.json` 49 | 50 | ```json 51 | { 52 | "type": "module", 53 | "scripts": { 54 | "start": "node esbuild.config.js -w", 55 | "build": "node esbuild.config.js" 56 | } 57 | } 58 | ``` 59 | 60 |
61 | 62 | ### Includes 63 | 64 | [esbuild](https://github.com/evanw/esbuild)   →   Extremely fast bundler and minifier. 65 | 66 | [Serve 🍛](https://github.com/nativew/serve)   →   Ultralight http server with live reload. 67 | 68 |
69 | 70 | ### Check 71 | 72 | [esbuild-plugin-pipe](https://github.com/nativew/esbuild-plugin-pipe)   →   Pipe esbuild plugins output. 73 | 74 | [esbuild-plugin-babel](https://github.com/nativew/esbuild-plugin-babel)   →   Babel plugin for esbuild. 75 | 76 | [esbuild-plugin-svg](https://github.com/nativew/esbuild-plugin-svg)   →   Svg files import plugin for esbuild. 77 | 78 | [esbuild-plugin-postcss-literal](https://github.com/nativew/esbuild-plugin-postcss-literal)   →   PostCSS tagged template literals plugin for esbuild. 79 | 80 |
81 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import esbuild from 'esbuild'; 2 | import serve, { error, log } from 'create-serve'; 3 | 4 | export const isWatch = process.argv.includes('-w'); 5 | 6 | const esbuildServe = async (options = {}, serveOptions = {}) => { 7 | esbuild 8 | .build({ 9 | ...options, 10 | watch: isWatch && { 11 | onRebuild(err) { 12 | serve.update(); 13 | err ? error('× Failed') : log('✓ Updated'); 14 | } 15 | } 16 | }) 17 | .catch(() => process.exit(1)); 18 | 19 | if (isWatch) { 20 | serve.start(serveOptions); 21 | } 22 | }; 23 | 24 | export default esbuildServe; 25 | --------------------------------------------------------------------------------