Skip to content

Commit aa4e8f4

Browse files
committed
fix: over-preloading due to inaccurate bundle-graph static import graph
1 parent 30026d9 commit aa4e8f4

File tree

4 files changed

+152
-134
lines changed

4 files changed

+152
-134
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
"prettier-plugin-tailwindcss": "0.6.14",
150150
"pretty-quick": "4.2.2",
151151
"prompts": "2.4.2",
152-
"rollup": ">= 4.39.0",
152+
"rollup": ">= 4.52.0",
153153
"semver": "7.7.2",
154154
"simple-git-hooks": "2.13.1",
155155
"snoop": "1.0.4",

packages/qwik/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"dependencies": {
2828
"csstype": "^3.1.3",
2929
"launch-editor": "^2.11.1",
30-
"rollup": ">= ^4.39.0"
30+
"rollup": ">= ^4.52.0"
3131
},
3232
"devDependencies": {
3333
"@builder.io/qwik": "workspace:^",

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { Rollup } from 'vite';
2-
31
import type {
42
Diagnostic,
53
EntryStrategy,
@@ -18,6 +16,9 @@ import {
1816
type QwikPlugin,
1917
type QwikPluginOptions,
2018
} from './plugin';
19+
import type { OutputOptions, Plugin, PreRenderedChunk, RollupError } from 'rollup';
20+
import { version as rollupVersion } from 'rollup/package.json';
21+
import semver from 'semver';
2122

2223
type QwikRollupPluginApi = {
2324
getOptimizer: () => Optimizer;
@@ -129,10 +130,10 @@ export function qwikRollup(qwikRollupOpts: QwikRollupPluginOptions = {}): any {
129130

130131
export function normalizeRollupOutputOptions(
131132
qwikPlugin: QwikPlugin,
132-
rollupOutputOpts: Rollup.OutputOptions | Rollup.OutputOptions[] | undefined,
133+
rollupOutputOpts: OutputOptions | OutputOptions[] | undefined,
133134
useAssetsDir: boolean,
134135
outDir?: string
135-
): Rollup.OutputOptions | Rollup.OutputOptions[] {
136+
): OutputOptions | OutputOptions[] {
136137
if (Array.isArray(rollupOutputOpts)) {
137138
// make sure at least one output is present in every case
138139
if (!rollupOutputOpts.length) {
@@ -153,10 +154,10 @@ export function normalizeRollupOutputOptions(
153154

154155
export function normalizeRollupOutputOptionsObject(
155156
qwikPlugin: QwikPlugin,
156-
rollupOutputOptsObj: Rollup.OutputOptions | undefined,
157+
rollupOutputOptsObj: OutputOptions | undefined,
157158
useAssetsDir: boolean
158-
): Rollup.OutputOptions {
159-
const outputOpts: Rollup.OutputOptions = { ...rollupOutputOptsObj };
159+
): OutputOptions {
160+
const outputOpts: OutputOptions = { ...rollupOutputOptsObj };
160161
const opts = qwikPlugin.getOptions();
161162
const optimizer = qwikPlugin.getOptimizer();
162163
const manualChunks = qwikPlugin.manualChunks;
@@ -170,7 +171,7 @@ export function normalizeRollupOutputOptionsObject(
170171
: assetFileNames;
171172
}
172173

173-
let fileName: string | ((chunkInfo: Rollup.PreRenderedChunk) => string) | undefined;
174+
let fileName: string | ((chunkInfo: PreRenderedChunk) => string) | undefined;
174175
if (opts.buildMode === 'production' && !opts.debug) {
175176
fileName = 'build/q-[hash].js';
176177
} else {
@@ -199,15 +200,14 @@ export function normalizeRollupOutputOptionsObject(
199200
};
200201
}
201202
// client development/debug output
202-
const getFilePath = (fileNamePattern: string | ((info: Rollup.PreRenderedChunk) => string)) =>
203+
const getFilePath = (fileNamePattern: string | ((info: PreRenderedChunk) => string)) =>
203204
typeof fileNamePattern === 'string'
204205
? useAssetsDir
205206
? `${opts.assetsDir}/${fileNamePattern}`
206207
: fileNamePattern
207208
: useAssetsDir
208-
? (chunkInfo: Rollup.PreRenderedChunk) =>
209-
`${opts.assetsDir}/${fileNamePattern(chunkInfo)}`
210-
: (chunkInfo: Rollup.PreRenderedChunk) => fileNamePattern(chunkInfo);
209+
? (chunkInfo: PreRenderedChunk) => `${opts.assetsDir}/${fileNamePattern(chunkInfo)}`
210+
: (chunkInfo: PreRenderedChunk) => fileNamePattern(chunkInfo);
211211

212212
if (!outputOpts.entryFileNames) {
213213
outputOpts.entryFileNames = getFilePath(fileName);
@@ -253,12 +253,20 @@ export function normalizeRollupOutputOptionsObject(
253253
*/
254254
outputOpts.hoistTransitiveImports = false;
255255

256+
if ('onlyExplicitManualChunks' in outputOpts) {
257+
outputOpts.onlyExplicitManualChunks = true;
258+
} else {
259+
console.warn(
260+
`⚠️ Outdated rollup version detected. For the latest and greatest, we recommend to update to rollup@^4.52.0. This can improve preloading performance and reduce cache invalidation for a snappier user experience.`
261+
);
262+
}
263+
256264
return outputOpts;
257265
}
258266

259267
export function createRollupError(id: string, diagnostic: Diagnostic) {
260268
const loc = diagnostic.highlights[0] ?? {};
261-
const err: Rollup.RollupError = Object.assign(new Error(diagnostic.message), {
269+
const err: RollupError = Object.assign(new Error(diagnostic.message), {
262270
id,
263271
plugin: 'qwik',
264272
loc: {
@@ -352,5 +360,5 @@ export interface QwikRollupPluginOptions {
352360
experimental?: (keyof typeof ExperimentalFeatures)[];
353361
}
354362
export { ExperimentalFeatures } from './plugin';
355-
type P<T> = Rollup.Plugin<T> & { api: T };
363+
type P<T> = Plugin<T> & { api: T };
356364
export interface QwikRollupPlugin extends P<QwikRollupPluginApi> {}

0 commit comments

Comments
 (0)