Skip to content

Commit

Permalink
fix: test another way
Browse files Browse the repository at this point in the history
  • Loading branch information
huang-julien committed Apr 2, 2023
1 parent bdf251e commit be68f98
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
24 changes: 17 additions & 7 deletions packages/nuxt/src/pages/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,27 @@ export default defineNuxtModule({
)
})

// Extract macros from pages
const pageMetaOptions: PageMetaPluginOptions = {
dev: nuxt.options.dev,
sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client,
dirs: nuxt.options._layers.map(
layer => resolve(layer.config.srcDir, layer.config.dir?.pages || 'pages')
)
}

nuxt.hook('modules:done', async () => {
const pages = await resolvePagesRoutes()
await nuxt.callHook('pages:extend', pages)
// Extract macros from pages
const pageMetaOptions: PageMetaPluginOptions = {
dev: nuxt.options.dev,
sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client,

nuxt.options.vite.plugins?.unshift(PageMetaPlugin.vite({
...pageMetaOptions,
pages
}
addVitePlugin(PageMetaPlugin.vite(pageMetaOptions))
addWebpackPlugin(PageMetaPlugin.webpack(pageMetaOptions))
}))
nuxt.options?.webpack.plugins.unshift(PageMetaPlugin.webpack({
...pageMetaOptions,
pages
}))
})

// Add prefetching support for middleware & layouts
Expand Down
4 changes: 3 additions & 1 deletion packages/nuxt/src/pages/page-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { isAbsolute, normalize } from 'pathe'
import type { NuxtPage } from '@nuxt/schema'

export interface PageMetaPluginOptions {
dirs: Array<string|RegExp>
dev?: boolean
sourcemap?: boolean
pages?: NuxtPage[]
Expand Down Expand Up @@ -42,8 +43,9 @@ export const PageMetaPlugin = createUnplugin((options: PageMetaPluginOptions) =>
transformInclude (id) {
const query = parseMacroQuery(id)
id = normalize(id)
const isPagesDir = options.dirs.some(dir => typeof dir === 'string' ? id.startsWith(dir) : dir.test(id))
const isPage = options.pages?.some(p => p.file?.startsWith(id))
if (!isPage && !query.macro) { return false }
if ((!isPage && !isPagesDir) && !query.macro) { return false }

const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href))
return /\.(m?[jt]sx?|vue)/.test(pathname)
Expand Down

0 comments on commit be68f98

Please sign in to comment.