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

Commit

Permalink
refactor: variables => exports
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jul 21, 2022
1 parent 18d4d1e commit f49c7c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/kit/src/internal/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ const importSources = (sources: string | string[], root: string, { lazy = false
if (!Array.isArray(sources)) {
sources = [sources]
}
const variables: string[] = []
const exports: string[] = []
const imports: string[] = []
for (const src of sources) {
const path = relative(root, src)
const variable = genSafeVariableName(path).replace(/_(45|46|47)/g, '_') + '_' + hash(path)
variables.push(variable)
exports.push(variable)
imports.push(lazy
? `const ${variable} = ${genDynamicImport(src, { comment: `webpackChunkName: ${JSON.stringify(src)}` })}`
: genImport(src, variable)
)
}
return {
variables,
exports,
imports
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/nuxt/src/core/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ export const clientPluginTemplate = {
getContents (ctx: TemplateContext) {
const clientPlugins = ctx.app.plugins.filter(p => !p.mode || p.mode !== 'server')
const rootDir = ctx.nuxt.options.rootDir
const { variables, imports } = templateUtils.importSources(clientPlugins.map(p => p.src), rootDir)
const { imports, exports } = templateUtils.importSources(clientPlugins.map(p => p.src), rootDir)
return [
...imports,
`export default ${genArrayFromRaw(variables)}`
`export default ${genArrayFromRaw(exports)}`
].join('\n')
}
}
Expand All @@ -62,13 +62,13 @@ export const serverPluginTemplate = {
getContents (ctx: TemplateContext) {
const serverPlugins = ctx.app.plugins.filter(p => !p.mode || p.mode !== 'client')
const rootDir = ctx.nuxt.options.rootDir
const { variables, imports } = templateUtils.importSources(serverPlugins.map(p => p.src), rootDir)
const { imports, exports } = templateUtils.importSources(serverPlugins.map(p => p.src), rootDir)
return [
"import preload from '#app/plugins/preload.server'",
...imports,
`export default ${genArrayFromRaw([
'preload',
...variables
...exports
])}`
].join('\n')
}
Expand Down

0 comments on commit f49c7c8

Please sign in to comment.