Skip to content

Commit

Permalink
Add watch function to guide, in alignment with updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
cynic authored Mar 29, 2024
1 parent e94eef6 commit 93e20cb
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,39 @@ and add the following code to it:
const esbuild = require('esbuild');
const ElmPlugin = require('esbuild-plugin-elm');

esbuild.build({
entryPoints: ['src/index.js'],
bundle: true,
outdir: '../js',
watch: process.argv.includes('--watch'),
plugins: [
ElmPlugin({
debug: true,
clearOnWatch: true,
}),
],
}).catch(_e => process.exit(1))
const isProduction = process.env.MIX_ENV === "prod"

async function watch() {
const ctx = await esbuild.context({
entryPoints: ['src/index.js'],
bundle: true,
outfile: '../js/elm.js',
plugins: [
ElmPlugin({
debug: true
}),
],
}).catch(_e => process.exit(1))
await ctx.watch()
}


async function build() {
await esbuild.build({
entryPoints: ['src/index.js'],
bundle: true,
minify: true,
outfile: '../js/elm.js',
plugins: [
ElmPlugin(),
],
}).catch(_e => process.exit(1))
}

if (isProduction)
build()
else
watch()
```

Ref:
Expand Down Expand Up @@ -495,4 +516,4 @@ gzip elm.min.js
Now it's **33kb**.
(488-33)/488 = **93%** bandwidth saving.
-->
-->

0 comments on commit 93e20cb

Please sign in to comment.