2021-11-28 10:05:40 +00:00
|
|
|
|
/* eslint-disable */
|
|
|
|
|
const fs = require('fs')
|
|
|
|
|
const esbuild = require('esbuild')
|
|
|
|
|
const { gzip } = require('zlib')
|
|
|
|
|
const pkg = require('../package.json')
|
|
|
|
|
|
2021-12-22 00:14:38 +00:00
|
|
|
|
const { log: jslog } = console
|
|
|
|
|
|
2021-11-28 10:05:40 +00:00
|
|
|
|
async function main() {
|
|
|
|
|
if (fs.existsSync('./dist')) {
|
|
|
|
|
fs.rmSync('./dist', { recursive: true }, (e) => {
|
|
|
|
|
if (e) {
|
|
|
|
|
throw e
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
esbuild.buildSync({
|
|
|
|
|
entryPoints: ['./src/index.ts'],
|
|
|
|
|
outdir: 'dist/cjs',
|
|
|
|
|
minify: false,
|
|
|
|
|
bundle: true,
|
|
|
|
|
format: 'cjs',
|
|
|
|
|
target: 'es6',
|
|
|
|
|
tsconfig: './tsconfig.build.json',
|
|
|
|
|
metafile: false,
|
|
|
|
|
sourcemap: true,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const esmResult = esbuild.buildSync({
|
|
|
|
|
entryPoints: ['./src/index.ts'],
|
|
|
|
|
outdir: 'dist/esm',
|
|
|
|
|
minify: false,
|
|
|
|
|
bundle: true,
|
|
|
|
|
format: 'esm',
|
|
|
|
|
target: 'es6',
|
|
|
|
|
tsconfig: './tsconfig.build.json',
|
|
|
|
|
metafile: true,
|
|
|
|
|
sourcemap: true,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const esmSize = Object.values(esmResult.metafile.outputs).reduce(
|
|
|
|
|
(acc, { bytes }) => acc + bytes,
|
|
|
|
|
0
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
fs.readFile('./dist/esm/index.js', (_err, data) => {
|
|
|
|
|
gzip(data, (_err, result) => {
|
2021-12-22 00:14:38 +00:00
|
|
|
|
jslog(
|
2021-11-28 10:05:40 +00:00
|
|
|
|
`✔ ${pkg.name}: Built package. ${(esmSize / 1000).toFixed(2)}kb (${(
|
|
|
|
|
result.length / 1000
|
|
|
|
|
).toFixed(2)}kb minified)`
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
} catch (e) {
|
2021-12-22 00:14:38 +00:00
|
|
|
|
jslog(`× ${pkg.name}: Build failed due to an error.`)
|
|
|
|
|
jslog(e)
|
2021-11-28 10:05:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main()
|