Skip to content

Commit

Permalink
fix: rspack plugin transform includes everything
Browse files Browse the repository at this point in the history
  • Loading branch information
孙权 committed Nov 14, 2023
1 parent 7a63e13 commit 98c20aa
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/rspack/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'path'
import type { RspackPluginInstance, RuleSetUseItem } from '@rspack/core'
import { toArray } from '../utils'
import { normalizeAbsolutePath, toArray } from '../utils'
import type {
UnpluginContextMeta,
UnpluginFactory,
Expand Down Expand Up @@ -47,15 +47,28 @@ export function getRspackPlugin<UserOptions = Record<string, never>>(

// transform hook
if (plugin.transform) {
const use: RuleSetUseItem = {
loader: TRANSFORM_LOADER,
options: { plugin },
}
const useLoader: RuleSetUseItem[] = [
{
loader: TRANSFORM_LOADER,
options: { plugin },
},
]
const useNone: RuleSetUseItem[] = []

compiler.options.module.rules.unshift({
enforce: plugin.enforce,
include: /.*/,
use,
use: (data) => {
if (data.resource == null)
return useNone

const id = normalizeAbsolutePath(
data.resource + (data.resourceQuery || ''),
)
if (!plugin.transformInclude || plugin.transformInclude(id))
return useLoader

return useNone
},
})
}

Expand Down

0 comments on commit 98c20aa

Please sign in to comment.