-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mjs
More file actions
51 lines (48 loc) · 1.2 KB
/
build.mjs
File metadata and controls
51 lines (48 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import path from 'node:path';
import * as esbuild from 'esbuild';
import { sassPlugin } from 'esbuild-sass-plugin';
import copy from 'esbuild-copy-static-files';
import postcss from 'postcss';
import postcssUrl from 'postcss-url';
const isWatch = process.argv.includes('--watch');
const ctx = await esbuild.context({
entryPoints: [
'src/client/main.ts',
'src/styles/main.scss'
],
bundle: true,
outdir: 'dist/build',
platform: 'browser',
target: ['es2017'],
external: ['/assets/*'],
plugins: [
copy({
src: './node_modules/govuk-frontend/dist/govuk/assets',
dest: './public/assets',
dereference: true
}),
sassPlugin({
loadPaths: [
path.resolve('./node_modules'),
path.resolve('./src')
],
async transform(source) {
const { css } = await postcss([
postcssUrl({
// Leave absolute URLs as-is
filter: (asset) => !asset.url.startsWith('/'),
})
]).process(source, { from: undefined });
return css;
}
})
],
minify: !isWatch,
});
if (isWatch) {
await ctx.watch();
console.log("Watching for changes...");
} else {
await ctx.rebuild();
await ctx.dispose();
}