forked from heybourn/headwind
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.mjs
70 lines (62 loc) · 1.81 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
70
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import esbuild from 'esbuild'
/**
* @returns {import('esbuild').Plugin}
*/
function patchRecast() {
return {
// https://github.com/benjamn/recast/issues/611
name: 'patch-recast',
setup(build) {
build.onLoad({ filter: /recast\/lib\/patcher\.js$/ }, async (args) => {
let original = await fs.promises.readFile(args.path, 'utf8')
return {
contents: original
.replace(
'var nls = needsLeadingSpace(lines, oldNode.loc, newLines);',
'var nls = oldNode.type !== "TemplateElement" && needsLeadingSpace(lines, oldNode.loc, newLines);',
)
.replace(
'var nts = needsTrailingSpace(lines, oldNode.loc, newLines)',
'var nts = oldNode.type !== "TemplateElement" && needsTrailingSpace(lines, oldNode.loc, newLines)',
),
}
})
},
}
}
/**
* @returns {import('esbuild').Plugin}
*/
function copyPreflightFromDistToBaseDist() {
return {
name: 'copy-preflight',
setup(build) {
build.onEnd(() =>
fs.promises.copyFile(
path.resolve(__dirname, './dist/css/node_modules/tailwindcss/lib/css/preflight.css'),
path.resolve(__dirname, './dist/css/preflight.css'),
),
)
},
}
}
const __dirname = path.dirname(fileURLToPath(import.meta.url))
let context = await esbuild.context({
bundle: true,
platform: 'node',
target: 'node14.21.3',
external: ["vscode"],
minify: true,
entryPoints: [path.resolve(__dirname, './src/loader.js')],
outfile: path.resolve(__dirname, './dist/index.js'),
format: 'cjs',
plugins: [patchRecast(), copyPreflightFromDistToBaseDist()],
})
await context.rebuild()
if (process.argv.includes('--watch')) {
await context.watch()
}
await context.dispose()