Skip to content

Commit ca12642

Browse files
committed
fix: qwikloader.cjs missing in non esm environments
1 parent b76adc2 commit ca12642

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

packages/qwik/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@
111111
"require": "./dist/optimizer.cjs"
112112
},
113113
"./preloader": {
114-
"import": "./dist/preloader.mjs"
114+
"import": "./dist/preloader.mjs",
115+
"require": "./dist/preloader.cjs"
115116
},
116117
"./server.cjs": "./dist/server.cjs",
117118
"./server.mjs": "./dist/server.mjs",

packages/qwik/src/optimizer/src/manifest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { OutputBundle } from 'rollup';
2-
import { QWIK_PRELOADER_REAL_ID, type NormalizedQwikPluginOptions } from './plugins/plugin';
2+
import { type NormalizedQwikPluginOptions } from './plugins/plugin';
33
import type { GlobalInjections, Path, QwikBundle, QwikManifest, SegmentAnalysis } from './types';
44

55
// This is just the initial prioritization of the symbols and entries
@@ -482,7 +482,7 @@ export function generateManifestFromBundles(
482482
.map((m) => path.relative(opts.rootDir, m));
483483
if (modulePaths.length > 0) {
484484
bundle.origins = modulePaths;
485-
if (modulePaths.some((m) => m.endsWith(QWIK_PRELOADER_REAL_ID))) {
485+
if (modulePaths.some((m) => /[/\\]qwik[/\\]dist[/\\]preloader\.[cm]js$/.test(m))) {
486486
manifest.preloader = bundleFileName;
487487
} else if (modulePaths.some((m) => /[/\\]qwik[/\\]dist[/\\]core\.[^/]*js$/.test(m))) {
488488
manifest.core = bundleFileName;

packages/qwik/src/optimizer/src/plugins/plugin.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -936,10 +936,14 @@ export const manifest = ${JSON.stringify(serverManifest)};\n`;
936936
}
937937

938938
function manualChunks(id: string, { getModuleInfo }: Rollup.ManualChunkMeta) {
939-
// The preloader has to stay in a separate chunk if it's a client build
940-
// the vite preload helper must be included or to prevent breaking circular dependencies
941939
if (opts.target === 'client') {
942-
if (id.endsWith(QWIK_PRELOADER_REAL_ID) || id === '\0vite/preload-helper.js') {
940+
if (
941+
// The preloader has to stay in a separate chunk if it's a client build
942+
// the vite preload helper must be included to prevent breaking circular dependencies
943+
id.endsWith('@builder.io/qwik/build') ||
944+
/[/\\]qwik[/\\]dist[/\\]preloader\.[cm]js$/.test(id) ||
945+
id === '\0vite/preload-helper.js'
946+
) {
943947
return 'qwik-preloader';
944948
} else if (/qwik[\\/]dist[\\/]qwikloader\.js$/.test(id)) {
945949
return 'qwik-loader';
@@ -1090,7 +1094,6 @@ export const QWIK_CORE_SERVER = '@builder.io/qwik/server';
10901094
export const QWIK_CLIENT_MANIFEST_ID = '@qwik-client-manifest';
10911095

10921096
export const QWIK_PRELOADER_ID = '@builder.io/qwik/preloader';
1093-
export const QWIK_PRELOADER_REAL_ID = 'qwik/dist/preloader.mjs';
10941097

10951098
export const SRC_DIR_DEFAULT = 'src';
10961099

scripts/submodule-preloader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export async function submodulePreloader(config: BuildConfig) {
5555
copyPublicDir: false,
5656
lib: {
5757
entry: join(config.srcQwikDir, 'core/preloader'),
58-
formats: ['es'],
59-
fileName: () => 'preloader.mjs',
58+
formats: ['es', 'cjs'],
59+
fileName: (format) => (format === 'es' ? 'preloader.mjs' : 'preloader.cjs'),
6060
},
6161
rollupOptions: {
6262
external: ['@builder.io/qwik/build'],

0 commit comments

Comments
 (0)