diff --git a/src/types.ts b/src/types.ts index 6a4a34c6..d248a3be 100644 --- a/src/types.ts +++ b/src/types.ts @@ -30,6 +30,7 @@ export interface UnpluginOptions { export interface ResolvedUnpluginOptions extends UnpluginOptions { // injected internal objects __vfs?: VirtualModulesPlugin + __vfsModules?: Set __virtualModulePrefix: string } diff --git a/src/webpack/index.ts b/src/webpack/index.ts index 7d859acc..1b539ace 100644 --- a/src/webpack/index.ts +++ b/src/webpack/index.ts @@ -67,6 +67,7 @@ export function getWebpackPlugin ( vfs = new VirtualModulesPlugin() compiler.options.plugins.push(vfs) } + plugin.__vfsModules = new Set() plugin.__vfs = vfs const resolver = { @@ -88,7 +89,8 @@ export function getWebpackPlugin ( // we treat it as a virtual module if (!fs.existsSync(resolved)) { resolved = plugin.__virtualModulePrefix + request.request - vfs.writeModule(resolved, '') + plugin.__vfs!.writeModule(resolved, '') + plugin.__vfsModules!.add(resolved) } // construt the new request @@ -112,10 +114,10 @@ export function getWebpackPlugin ( } // load hook - if (plugin.load) { + if (plugin.load && plugin.__vfsModules) { compiler.options.module.rules.push({ - include () { - return true + include (id) { + return plugin.__vfsModules!.has(id) }, enforce: plugin.enforce, use: [{