-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.mjs
69 lines (64 loc) · 1.63 KB
/
build.mjs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import fs from 'node:fs'
import path from 'node:path'
import * as esbuild from 'esbuild'
import {sassPlugin} from 'esbuild-sass-plugin'
import { Marked } from 'marked'
import {markedHighlight} from 'marked-highlight'
import { gfmHeadingId } from 'marked-gfm-heading-id'
import hljs from 'highlight.js'
const marked = new Marked(
markedHighlight({
langPrefix: 'hljs language-',
highlight(code, lang) {
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
return hljs.highlight(code, { language }).value;
},
}),
gfmHeadingId(),
);
let markdownPlugin = {
name: 'markdown',
setup(build) {
build.onResolve({ filter: /\.md$/ }, args => ({
path: path.join(args.resolveDir, args.path),
namespace: 'markdown',
}))
build.onLoad({ filter: /.*/, namespace: 'markdown' }, async (args) => {
const md = await fs.promises.readFile(args.path, 'utf8')
return {
contents: marked.parse(md),
loader: 'text',
}
})
},
}
let ignoreFontsPlugin = {
name: 'ignore-fonts',
setup(build) {
// ignore font files imported in scss
build.onResolve({ filter: /\.woff2?$/ }, args => {
return { path: args.path, external: true }
})
},
}
await esbuild.build({
format: 'esm',
mainFields: ['browser', 'module', 'main'],
platform: 'neutral',
target: 'es2020',
sourcemap: false,
entryPoints: ['src/index.ts'],
bundle: true,
outfile: 'worker/index.mjs',
loader: {
'.html': 'text',
'.svg': 'text',
'.woff': 'empty',
'.woff2': 'empty',
},
plugins: [
markdownPlugin,
ignoreFontsPlugin,
sassPlugin({type: 'css-text'}),
],
})