2021-08-10 16:12:55 +00:00
|
|
|
|
/* eslint-disable */
|
|
|
|
|
const fs = require('fs')
|
|
|
|
|
const esbuild = require('esbuild')
|
2021-09-12 12:21:44 +00:00
|
|
|
|
const { gzip } = require('zlib')
|
2021-08-10 16:12:55 +00:00
|
|
|
|
|
|
|
|
|
const name = process.env.npm_package_name || ''
|
|
|
|
|
|
|
|
|
|
async function main() {
|
2021-09-06 12:04:12 +00:00
|
|
|
|
if (fs.existsSync('./dist')) {
|
|
|
|
|
fs.rmSync('./dist', { recursive: true }, (e) => {
|
|
|
|
|
if (e) {
|
|
|
|
|
throw e
|
|
|
|
|
}
|
|
|
|
|
})
|
2021-08-29 13:46:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-10 16:12:55 +00:00
|
|
|
|
try {
|
|
|
|
|
esbuild.buildSync({
|
|
|
|
|
entryPoints: ['./src/index.ts'],
|
|
|
|
|
outdir: 'dist/cjs',
|
2021-08-31 18:13:24 +00:00
|
|
|
|
minify: true,
|
2021-08-10 16:12:55 +00:00
|
|
|
|
bundle: true,
|
|
|
|
|
format: 'cjs',
|
|
|
|
|
target: 'es6',
|
|
|
|
|
jsxFactory: 'React.createElement',
|
|
|
|
|
jsxFragment: 'React.Fragment',
|
2021-08-14 15:46:21 +00:00
|
|
|
|
tsconfig: './tsconfig.build.json',
|
2021-08-10 16:12:55 +00:00
|
|
|
|
external: ['react', 'react-dom'],
|
2021-09-12 12:21:44 +00:00
|
|
|
|
metafile: true,
|
2021-08-10 16:12:55 +00:00
|
|
|
|
})
|
|
|
|
|
|
2021-09-12 12:21:44 +00:00
|
|
|
|
const esmResult = esbuild.buildSync({
|
2021-08-27 09:53:01 +00:00
|
|
|
|
entryPoints: ['./src/index.ts'],
|
|
|
|
|
outdir: 'dist/esm',
|
|
|
|
|
minify: true,
|
|
|
|
|
bundle: true,
|
|
|
|
|
format: 'esm',
|
|
|
|
|
target: 'es6',
|
|
|
|
|
tsconfig: './tsconfig.build.json',
|
|
|
|
|
jsxFactory: 'React.createElement',
|
|
|
|
|
jsxFragment: 'React.Fragment',
|
|
|
|
|
external: ['react', 'react-dom'],
|
2021-09-12 12:21:44 +00:00
|
|
|
|
metafile: true,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
let esmSize = 0
|
|
|
|
|
Object.values(esmResult.metafile.outputs).forEach((output) => {
|
|
|
|
|
esmSize += output.bytes
|
2021-08-27 09:53:01 +00:00
|
|
|
|
})
|
|
|
|
|
|
2021-09-12 12:21:44 +00:00
|
|
|
|
fs.readFile('./dist/esm/index.js', (_err, data) => {
|
|
|
|
|
gzip(data, (_err, result) => {
|
|
|
|
|
console.log(
|
|
|
|
|
`✔ ${name}: Built package. ${(esmSize / 1000).toFixed(2)}kb (${(
|
|
|
|
|
result.length / 1000
|
|
|
|
|
).toFixed(2)}kb minified)`
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
2021-08-10 16:12:55 +00:00
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log(`× ${name}: Build failed due to an error.`)
|
|
|
|
|
console.log(e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main()
|