Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

perf(nuxt): transform #imports to improve tree-shaking #5763

Merged
merged 8 commits into from
Jul 21, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: windows webpack
  • Loading branch information
antfu committed Jul 15, 2022
commit 5c47cc3534cfc13c33b964be5a2da1a752059a1d
2 changes: 2 additions & 0 deletions packages/nuxt/src/auto-imports/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createUnplugin } from 'unplugin'
import { parseQuery, parseURL } from 'ufo'
import { Unimport } from 'unimport'
import { AutoImportsOptions } from '@nuxt/schema'
import { normalize } from 'pathe'

export const TransformPlugin = createUnplugin(({ ctx, options, sourcemap }: {ctx: Unimport, options: Partial<AutoImportsOptions>, sourcemap?: boolean }) => {
return {
Expand Down Expand Up @@ -35,6 +36,7 @@ export const TransformPlugin = createUnplugin(({ ctx, options, sourcemap }: {ctx
}
},
async transform (code, id) {
id = normalize(id)
const isNodeModule = id.match(/[\\/]node_modules[\\/]/) && !options.transform?.include?.some(pattern => id.match(pattern))
// For modules in node_modules, we only transform `#imports` but not doing auto-imports
if (isNodeModule && !code.match(/(['"])#imports\1/)) {
Expand Down