Skip to content

Commit

Permalink
Merge pull request #136 from cynic/patch-1
Browse files Browse the repository at this point in the history
Add watch function to guide, in alignment with updated code
  • Loading branch information
nelsonic authored Mar 29, 2024
2 parents e94eef6 + 93e20cb commit 858818a
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 858818a

Please sign in to comment.