forked from extractus/feed-extractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
70 lines (59 loc) · 1.34 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
// build.js
import { readFileSync, writeFileSync, copyFileSync, rmSync, mkdirSync } from 'fs'
import { buildSync } from 'esbuild'
const pkg = JSON.parse(readFileSync('./package.json', { encoding: 'utf-8' }))
rmSync('dist', {
force: true,
recursive: true
})
mkdirSync('dist')
const buildTime = (new Date()).toISOString()
const comment = [
`// ${pkg.name}@${pkg.version}, by ${pkg.author}`,
`built with esbuild at ${buildTime}`,
`published under ${pkg.license} license`
].join(' - ')
const baseOpt = {
entryPoints: ['src/main.js'],
bundle: true,
charset: 'utf8',
target: ['es2020', 'node14'],
pure: ['console.log', 'debug', 'alert'],
legalComments: 'none',
minify: false,
sourcemap: false,
write: true
}
const esmVersion = {
...baseOpt,
platform: 'browser',
format: 'esm',
outfile: 'dist/feed-extractor.esm.js',
banner: {
js: comment
}
}
buildSync(esmVersion)
const cjsVersion = {
...baseOpt,
platform: 'node',
format: 'cjs',
mainFields: ['main'],
outfile: 'dist/cjs/feed-extractor.js',
banner: {
js: comment
}
}
buildSync(cjsVersion)
const cjspkg = {
name: pkg.name,
version: pkg.version,
main: './feed-extractor.js'
}
writeFileSync(
'dist/cjs/package.json',
JSON.stringify(cjspkg, null, ' '),
'utf8'
)
// copy types definition to cjs dir
copyFileSync('./index.d.ts', 'dist/cjs/index.d.ts')