Skip to content

Commit

Permalink
fix: always transform if transformInclude is not provided (compacti…
Browse files Browse the repository at this point in the history
…ble with rollup)
  • Loading branch information
antfu committed Jul 12, 2021
1 parent a4dce0e commit 624e0d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function getRollupPlugin <UserOptions = {}> (
name: options.name,
enforce: options.enforce,
transform (code, id) {
if (!hooks.transformInclude?.(id)) {
if (hooks.transformInclude && !hooks.transformInclude(id)) {
return null
}
return hooks.transform?.(code, id) || null
Expand Down
17 changes: 9 additions & 8 deletions src/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ export function getWebpackPlugin<UserOptions = {}> (
fs.writeFileSync(loaderPath, `
module.exports = async function(source, map) {
const callback = this.async()
if (!this._compiler || !this._compiler.$unplugin)
return callback(null, source, map)
const plugin = this._compiler.$unplugin['${options.name}']
if (!plugin)
return callback(null, source, map)
const res = await plugin.transform(source, this.resource)
if (typeof res !== 'string') {
if (res == null) {
callback(null, source, map)
}
else if (typeof res !== 'string') {
callback(null, res.code, res.map)
}
else {
Expand All @@ -43,7 +40,11 @@ module.exports = async function(source, map) {

compiler.options.module.rules.push({
include (id: string) {
return hooks.transformInclude?.(id)
if (hooks.transformInclude) {
return hooks.transformInclude(id)
} else {
return true
}
},
enforce: options.enforce,
use: [{
Expand Down

0 comments on commit 624e0d3

Please sign in to comment.