-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
89 lines (83 loc) · 2.41 KB
/
build.ts
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import fs from 'node:fs'
import path from 'node:path'
import * as rollup from 'rollup'
import * as esbuild from 'esbuild'
import * as SASS from 'sass'
import { version, dependencies } from './package.json'
const sass = (): esbuild.Plugin => ({
name: 'inline-sass',
setup({ onLoad, esbuild }) {
onLoad({ filter: /\.scss/ }, async args => {
if (args.suffix !== '?inline') return
const { css } = SASS.compile(args.path, { style: 'compressed' })
const { outputFiles } = await esbuild.build({
stdin: {
contents: css,
loader: 'css',
resolveDir: path.dirname(args.path),
sourcefile: args.path,
},
loader: {
".woff2": "dataurl",
".woff": "dataurl",
".ttf": "dataurl",
},
logLevel: 'silent',
bundle: true,
minify: true,
write: false,
outdir: 'dist',
legalComments: 'none',
})
const contents = outputFiles[0].text.trimEnd()
return { contents, loader: 'text' }
})
}
})
fs.rmSync('dist', { recursive: true, force: true })
let bundle = await rollup.rollup({
input: 'src/index.ts',
external: Object.keys(dependencies),
plugins: [{
name: 'esbuild',
async load(id) {
const { outputFiles } = await esbuild.build({
entryPoints: [id],
bundle: true,
format: 'esm',
outfile: id.replace(/\.ts$/, '.js'),
sourcemap: true,
write: false,
target: ['es2017'],
plugins: [sass()],
define: {
__VERSION__: JSON.stringify(version)
},
legalComments: 'none',
external: Object.keys(dependencies)
})
let code: any, map: any
for (const { path, text } of outputFiles) {
if (path.endsWith('.map')) map = text;
else code = text;
}
return { code, map }
}
}]
})
await Promise.all([
bundle.write({ file: 'dist/index.mjs', format: 'es', sourcemap: true, sourcemapExcludeSources: true }),
bundle.write({ file: 'dist/index.js', format: 'cjs', sourcemap: true, sourcemapExcludeSources: true, interop: 'auto', exports: 'named' }),
])
await bundle.close()
await esbuild.build({
entryPoints: ['src/index.ts'],
bundle: true,
target: ['es2017'],
plugins: [sass()],
logLevel: 'info',
minify: true,
outfile: 'dist/index.global.js',
legalComments: 'none',
globalName: 'NetlessAppQuill'
}).catch(() => process.exit(1))