Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: delay _importDynamic initialization #1753

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Changes from all commits
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
5 changes: 2 additions & 3 deletions packages/core/src/config/config-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ import type { Document, ResolvedRefMap } from '../resolve';

const DEFAULT_PROJECT_PLUGIN_PATHS = ['@theme/plugin.js', '@theme/plugin.cjs', '@theme/plugin.mjs'];

// Workaround for dynamic imports being transpiled to require by Typescript: https://github.com/microsoft/TypeScript/issues/43329#issuecomment-811606238
const _importDynamic = new Function('modulePath', 'return import(modulePath)');

// Cache instantiated plugins during a single execution
const pluginsCache: Map<string, Plugin> = new Map();

Expand Down Expand Up @@ -151,6 +148,8 @@ export async function resolvePlugins(
// @ts-ignore
requiredPlugin = __non_webpack_require__(absolutePluginPath);
} else {
// Workaround for dynamic imports being transpiled to require by Typescript: https://github.com/microsoft/TypeScript/issues/43329#issuecomment-811606238
const _importDynamic = new Function('modulePath', 'return import(modulePath)');
// you can import both cjs and mjs
const mod = await _importDynamic(pathToFileURL(absolutePluginPath).href);
requiredPlugin = mod.default || mod;
Expand Down
Loading