-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
80 lines (74 loc) · 2.13 KB
/
build.js
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
import fs from 'node:fs'
import path from 'node:path'
import * as rollup from 'rollup'
import * as esbuild from 'esbuild'
import { babel } from '@rollup/plugin-babel';
import { version } from './package.json'
import {nodeResolve} from '@rollup/plugin-node-resolve';
fs.rmSync('dist', { recursive: true, force: true })
let bundle = await rollup.rollup({
input: 'index.js',
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'],
define: {
__VERSION__: JSON.stringify(version)
},
legalComments: 'none'
})
let code, map;
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: 'index.js',
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'],
define: {
__VERSION__: JSON.stringify(version)
},
legalComments: 'none'
})
let code, map;
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: "NetlessFastboard" })
await bundle_iife.close()