Skip to content

Commit c267c44

Browse files
committed
fix(webpack): lazy import webpack
1 parent 19c95b1 commit c267c44

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/webpack/context.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { Compilation, Compiler, LoaderContext } from 'webpack'
1+
import type { Compilation, Compiler, LoaderContext, sources } from 'webpack'
22
import type { UnpluginBuildContext, UnpluginContext, UnpluginMessage } from '../types'
33
import { Buffer } from 'buffer'
4+
import { createRequire } from 'module'
45
import { resolve } from 'path'
56
import process from 'process'
67
import { Parser } from 'acorn'
7-
import * as webpack from 'webpack'
88

99
interface ContextOptions {
1010
addWatchFile: (file: string) => void
@@ -22,7 +22,9 @@ export function contextOptionsFromCompilation(compilation: Compilation): Context
2222
}
2323
}
2424

25-
export function getSource(fileSource: string | Uint8Array): webpack.sources.RawSource {
25+
const require = createRequire(import.meta.url)
26+
export function getSource(fileSource: string | Uint8Array): sources.RawSource {
27+
const webpack = require('webpack')
2628
return new webpack.sources.RawSource(
2729
typeof fileSource === 'string' ? fileSource : Buffer.from(fileSource.buffer),
2830
)

0 commit comments

Comments
 (0)