From 0cb9a4c51d0bc80506490ee0cd54a069993996ec Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 13 Dec 2022 10:30:12 +0000 Subject: [PATCH] refactor(nuxt): do not add all composable auto-imports to `globalThis` (#9630) --- packages/nuxt/src/imports/module.ts | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/packages/nuxt/src/imports/module.ts b/packages/nuxt/src/imports/module.ts index 32dfa7f74e..674e65db66 100644 --- a/packages/nuxt/src/imports/module.ts +++ b/packages/nuxt/src/imports/module.ts @@ -1,7 +1,7 @@ -import { addVitePlugin, addWebpackPlugin, defineNuxtModule, addTemplate, resolveAlias, useNuxt, addPluginTemplate, updateTemplates } from '@nuxt/kit' +import { addVitePlugin, addWebpackPlugin, defineNuxtModule, addTemplate, resolveAlias, useNuxt, updateTemplates } from '@nuxt/kit' import { isAbsolute, join, relative, resolve, normalize } from 'pathe' import type { Import, Unimport } from 'unimport' -import { createUnimport, scanDirExports, toImports } from 'unimport' +import { createUnimport, scanDirExports } from 'unimport' import type { ImportsOptions, ImportPresetWithDeprecation } from '@nuxt/schema' import { TransformPlugin } from './transform' import { defaultPresets } from './presets' @@ -65,23 +65,9 @@ export default defineNuxtModule>({ }) nuxt.options.alias['#imports'] = join(nuxt.options.buildDir, 'imports') - // Transpile and injection - if (nuxt.options.dev && options.global) { - // Add all imports to globalThis in development mode - addPluginTemplate({ - filename: 'imports.mjs', - getContents: async () => { - const imports = await ctx.getImports() - const importStatement = toImports(imports) - const globalThisSet = imports.map(i => `globalThis.${i.as} = ${i.as};`).join('\n') - return `${importStatement}\n\n${globalThisSet}\n\nexport default () => {};` - } - }) - } else { - // Transform to inject imports in production mode - addVitePlugin(TransformPlugin.vite({ ctx, options, sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client })) - addWebpackPlugin(TransformPlugin.webpack({ ctx, options, sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client })) - } + // Transform to inject imports in production mode + addVitePlugin(TransformPlugin.vite({ ctx, options, sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client })) + addWebpackPlugin(TransformPlugin.webpack({ ctx, options, sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client })) const regenerateImports = async () => { ctx.clearDynamicImports()