Skip to content

Commit

Permalink
fix: dynamically require webpack-sources
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 4, 2024
1 parent cc66aa3 commit 6d4d2b1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/webpack/context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { resolve } from 'path'
import { Buffer } from 'buffer'
import process from 'process'
import sources from 'webpack-sources'
import { createRequire } from 'module'
import type { Compilation, LoaderContext } from 'webpack'
import { Parser } from 'acorn'
import type { UnpluginBuildContext, UnpluginContext, UnpluginMessage } from '../types'
Expand All @@ -23,6 +23,9 @@ export function contextOptionsFromCompilation(compilation: Compilation): Context
}

export function createBuildContext(options: ContextOptions, compilation?: Compilation): UnpluginBuildContext {
const require = createRequire(import.meta.url)
const sources = require('webpack-sources') as typeof import('webpack-sources')

return {
parse(code: string, opts: any = {}) {
return Parser.parse(code, {
Expand Down

0 comments on commit 6d4d2b1

Please sign in to comment.