Skip to content

Commit

Permalink
Use esbuild for building assets
Browse files Browse the repository at this point in the history
  • Loading branch information
cruessler committed Apr 7, 2023
1 parent 4e9350e commit fab34bb
Show file tree
Hide file tree
Showing 5 changed files with 816 additions and 31 deletions.
63 changes: 63 additions & 0 deletions assets/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 2023-04-07
//
// This file does not work with esbuild > 0.16 as esbuild’s API has changed in
// 0.17.
//
// esbuild-sass-plugin is pinned to version < 2.6 because versions > 2.5 require
// esbuild 0.17.
//
// https://github.com/evanw/esbuild/blob/main/CHANGELOG.md#0170

import esbuild from 'esbuild';
import ElmPlugin from 'esbuild-plugin-elm';
import { sassPlugin } from 'esbuild-sass-plugin';

const args = process.argv.slice(2);
const watch = args.includes('--watch');
const deploy = args.includes('--deploy');

const plugins = [
ElmPlugin({
cwd: './elm/',
debug: !deploy,
optimize: deploy,
clearOnWatch: watch,
}),
sassPlugin(),
];

let opts = {
entryPoints: ['js/app.js'],
bundle: true,
target: 'es2017',
outdir: '../priv/static/assets',
logLevel: 'info',
plugins,
};

if (watch) {
opts = {
...opts,
watch,
sourcemap: 'inline',
};
}

if (deploy) {
opts = {
...opts,
minify: true,
};
}

const promise = esbuild.build(opts);

if (watch) {
promise.then((_result) => {
process.stdin.on('close', () => {
process.exit(0);
});

process.stdin.resume();
});
}
Loading

0 comments on commit fab34bb

Please sign in to comment.