Repository navigation
Expand file tree
/
Copy pathbundle.js
More file actions
53 lines (46 loc) · 1.44 KB
/
Copy pathbundle.js
File metadata and controls
53 lines (46 loc) · 1.44 KB
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
import { writeFileSync } from 'fs';
import { resolve, basename } from 'path';
import esbuild from 'esbuild';
import { createRequire } from 'module';
const { version } = createRequire(import.meta.url)('../package.json');
async function build() {
const genModules = {
[resolve('lib/version.js')]: `export const version = "${version}";`,
[resolve('cjs/version.cjs')]: `module.exports = "${version}";`
};
const genModulesFilter = new RegExp('(' + Object.keys(genModules).join('|').replace(/\./g, '\\.') + ')$');
const plugins = [{
name: 'replace',
setup({ onLoad }) {
onLoad({ filter: genModulesFilter }, args => ({
contents: genModules[args.path]
}));
}
}];
await Promise.all([
esbuild.build({
entryPoints: ['lib/index.js'],
outfile: 'dist/csso.js',
format: 'iife',
globalName: 'csso',
bundle: true,
minify: true,
logLevel: 'info',
plugins
}),
esbuild.build({
entryPoints: ['lib/index.js'],
outfile: 'dist/csso.esm.js',
format: 'esm',
bundle: true,
minify: true,
logLevel: 'info',
plugins
})
]);
for (const [key, value] of Object.entries(genModules)) {
const fn = basename(key);
writeFileSync(`dist/${fn}`, value);
}
}
build();