+
+const isDevelopmentBuild = env.BUILD === 'development'
+const isAnalyzeBuild = env.ANALYZE
+const isDocumentationBuild = env.DOCUMENTATION
+const sourcemap = env.SOURCEMAP !== 'false'
+
+const maxWorkers = Math.floor(availableParallelism() / 2)
+
+export default defineConfig([
+ {
+ input: './src/index.ts',
+ strictDeprecations: true,
+ output: [
+ {
+ format: 'cjs',
+ ...(isDevelopmentBuild && {
+ dir: './lib',
+ preserveModules: true,
+ preserveModulesRoot: './src'
+ }),
+ ...(!isDevelopmentBuild && {
+ file: './lib/index.js',
+ plugins: [terser({ maxWorkers })]
+ }),
+ ...(sourcemap && {
+ sourcemap
+ })
+ },
+ {
+ format: 'esm',
+ ...(isDevelopmentBuild && {
+ dir: './lib',
+ entryFileNames: '[name].mjs',
+ chunkFileNames: '[name]-[hash].mjs',
+ preserveModules: true,
+ preserveModulesRoot: './src'
+ }),
+ ...(!isDevelopmentBuild && {
+ file: './lib/index.mjs',
+ plugins: [terser({ maxWorkers })]
+ }),
+ ...(sourcemap && {
+ sourcemap
+ })
+ }
+ ],
+ external: [
+ 'node:async_hooks',
+ 'node:cluster',
+ 'node:crypto',
+ 'node:events',
+ 'node:fs',
+ 'node:os',
+ 'node:perf_hooks',
+ 'node:worker_threads'
+ ],
+ plugins: [
+ typescript({
+ tsconfig: './tsconfig.build.json'
+ }),
+ del({
+ targets: ['./lib/*']
+ }),
+ isAnalyzeBuild && analyze(),
+ isDocumentationBuild && command('pnpm typedoc')
+ ]
+ },
+ {
+ input: './lib/dts/index.d.ts',
+ output: [{ format: 'esm', file: './lib/index.d.ts' }],
+ external: [
+ 'node:async_hooks',
+ 'node:cluster',
+ 'node:events',
+ 'node:perf_hooks',
+ 'node:worker_threads'
+ ],
+ plugins: [
+ dts(),
+ del({
+ targets: ['./lib/dts'],
+ hook: 'buildEnd'
+ }),
+ isAnalyzeBuild && analyze()
+ ]
+ }
+])