@@ -78,6 +78,7 @@ export function qwikRollup(qwikRollupOpts: QwikRollupPluginOptions = {}): any {
78
78
79
79
outputOptions ( rollupOutputOpts ) {
80
80
return normalizeRollupOutputOptionsObject (
81
+ qwikPlugin . getOptimizer ( ) ,
81
82
qwikPlugin . getOptions ( ) ,
82
83
rollupOutputOpts ,
83
84
false ,
@@ -160,6 +161,7 @@ export function qwikRollup(qwikRollupOpts: QwikRollupPluginOptions = {}): any {
160
161
}
161
162
162
163
export function normalizeRollupOutputOptions (
164
+ optimizer : Optimizer ,
163
165
opts : NormalizedQwikPluginOptions ,
164
166
rollupOutputOpts : Rollup . OutputOptions | Rollup . OutputOptions [ ] | undefined ,
165
167
useAssetsDir : boolean ,
@@ -173,18 +175,31 @@ export function normalizeRollupOutputOptions(
173
175
}
174
176
175
177
return rollupOutputOpts . map ( ( outputOptsObj ) => ( {
176
- ...normalizeRollupOutputOptionsObject ( opts , outputOptsObj , useAssetsDir , manualChunks ) ,
178
+ ...normalizeRollupOutputOptionsObject (
179
+ optimizer ,
180
+ opts ,
181
+ outputOptsObj ,
182
+ useAssetsDir ,
183
+ manualChunks
184
+ ) ,
177
185
dir : outDir || outputOptsObj . dir ,
178
186
} ) ) ;
179
187
}
180
188
181
189
return {
182
- ...normalizeRollupOutputOptionsObject ( opts , rollupOutputOpts , useAssetsDir , manualChunks ) ,
190
+ ...normalizeRollupOutputOptionsObject (
191
+ optimizer ,
192
+ opts ,
193
+ rollupOutputOpts ,
194
+ useAssetsDir ,
195
+ manualChunks
196
+ ) ,
183
197
dir : outDir || rollupOutputOpts ?. dir ,
184
198
} ;
185
199
}
186
200
187
201
export function normalizeRollupOutputOptionsObject (
202
+ optimizer : Optimizer ,
188
203
opts : NormalizedQwikPluginOptions ,
189
204
rollupOutputOptsObj : Rollup . OutputOptions | undefined ,
190
205
useAssetsDir : boolean ,
@@ -201,9 +216,31 @@ export function normalizeRollupOutputOptionsObject(
201
216
? `${ opts . assetsDir } /${ assetFileNames } `
202
217
: assetFileNames ;
203
218
}
204
- // Friendly name in dev or preview with debug mode
205
- const fileName =
206
- opts . buildMode == 'production' && ! opts . debug ? 'build/q-[hash].js' : 'build/[name].js' ;
219
+
220
+ let fileName : string | ( ( chunkInfo : Rollup . PreRenderedChunk ) => string ) | undefined ;
221
+ if ( opts . buildMode === 'production' && ! opts . debug ) {
222
+ fileName = 'build/q-[hash].js' ;
223
+ } else {
224
+ // Friendlier names in dev or preview with debug mode
225
+ fileName = ( chunkInfo ) => {
226
+ if ( chunkInfo . moduleIds . some ( ( id ) => id . endsWith ( 'core.prod.mjs' ) ) ) {
227
+ return 'build/core.js' ;
228
+ }
229
+ if ( chunkInfo . moduleIds . some ( ( id ) => id . endsWith ( 'qwik-city/lib/index.qwik.mjs' ) ) ) {
230
+ return 'build/qwik-city.js' ;
231
+ }
232
+
233
+ // some chunk names are absolute paths and rollup doesn't accept that so we must sanitize those instead of simply returning `build/[name].js`.
234
+ const path = optimizer . sys . path ;
235
+ const relativePath = path . relative ( optimizer . sys . cwd ( ) , chunkInfo . name ) ;
236
+ const sanitizedPath = relativePath
237
+ . replace ( / ^ ( \. \. \/ ) + / , '' )
238
+ . replace ( / ^ \/ + / , '' )
239
+ . replace ( / \/ / g, '-' ) ;
240
+
241
+ return `build/${ sanitizedPath } .js` ;
242
+ } ;
243
+ }
207
244
// client production output
208
245
if ( ! outputOpts . entryFileNames ) {
209
246
outputOpts . entryFileNames = useAssetsDir ? `${ opts . assetsDir } /${ fileName } ` : fileName ;
0 commit comments