Skip to content

Commit 4ef703c

Browse files
committed
feat: lazy load esbuild
1 parent 06e7f31 commit 4ef703c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
"prepublishOnly": "npm run test && npm run build",
2424
"test": "vitest run"
2525
},
26-
"peerDependencies": {
27-
"esbuild": "*"
28-
},
2926
"dependencies": {
3027
"lib-esm": "~0.3.0"
3128
},

src/optimizer.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import path from 'node:path'
33
import crypto from 'node:crypto'
44
import { createRequire, builtinModules } from 'node:module'
55
import type { Alias, Plugin, UserConfig } from 'vite'
6-
import esbuild from 'esbuild'
76
import libEsm from 'lib-esm'
87
import { COLOURS, node_modules } from 'vite-plugin-utils/function'
98
import { builtins } from './build-config'
@@ -191,12 +190,19 @@ function cjsBundling(args: {
191190
async function esmBundling(args: {
192191
name: string,
193192
entry: string,
194-
buildOptions?: esbuild.BuildOptions,
193+
buildOptions?: import('esbuild').BuildOptions,
195194
}) {
196195
const { name, entry, buildOptions } = args
197196
const { name_cjs, destname_cjs } = dest(name)
198197
if (cache.checkHash(destname_cjs)) return
199198

199+
let esbuild: typeof import('esbuild')
200+
try {
201+
esbuild = await import('esbuild')
202+
} catch {
203+
throw new Error('[Pre-Bundling] dependency "esbuild". Did you install it?')
204+
}
205+
200206
return esbuild.build({
201207
entryPoints: [entry],
202208
outfile: destname_cjs,

0 commit comments

Comments
 (0)