-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.ts
129 lines (121 loc) · 3.53 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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 { babel } from '@rollup/plugin-babel';
import { version, dependencies } from './package.json'
import {nodeResolve} from '@rollup/plugin-node-resolve';
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()
let bundle_iife = 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,
minify: true,
target: ['es2015'],
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 }
}
},
nodeResolve(),
babel({ babelHelpers: 'bundled', extensions: ['.ts'] })
]
})
await bundle_iife.write({ file: 'dist/index.global.js', format: 'iife', name: "NetlessAppQuill" })
// await esbuild.build({
// entryPoints: ['src/index.ts'],
// bundle: true,
// target: ['es2015'],
// plugins: [sass()],
// logLevel: 'info',
// minify: true,
// outfile: 'dist/index.global.js',
// legalComments: 'none',
// globalName: 'NetlessAppQuill'
// }).catch(() => process.exit(1))