@@ -18,6 +18,7 @@ import type { Plugin } from '../plugin'
18
18
import type { ResolvedConfig } from '../config'
19
19
import { toOutputFilePathInJS } from '../build'
20
20
import { genSourceMapUrl } from '../server/sourcemap'
21
+ import type { Environment } from '../environment'
21
22
import { removedPureCssFilesCache } from './css'
22
23
import { createParseErrorInfo } from './importAnalysis'
23
24
@@ -169,9 +170,10 @@ function preload(
169
170
* Build only. During serve this is performed as part of ./importAnalysis.
170
171
*/
171
172
export function buildImportAnalysisPlugin ( config : ResolvedConfig ) : Plugin {
172
- const ssr = ! ! config . build . ssr
173
- const isWorker = config . isWorker
174
- const insertPreload = ! ( ssr || ! ! config . build . lib || isWorker )
173
+ const getInsertPreload = ( environment : Environment ) =>
174
+ environment . config . consumer === 'client' &&
175
+ ! config . isWorker &&
176
+ ! config . build . lib
175
177
176
178
const renderBuiltUrl = config . experimental . renderBuiltUrl
177
179
const isRelativeBase = config . base === './' || config . base === ''
@@ -237,6 +239,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
237
239
return null
238
240
}
239
241
242
+ const insertPreload = getInsertPreload ( this . environment )
240
243
// when wrapping dynamic imports with a preload helper, Rollup is unable to analyze the
241
244
// accessed variables for treeshaking. This below tries to match common accessed syntax
242
245
// to "copy" it over to the dynamic import wrapped by the preload helper.
@@ -402,7 +405,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
402
405
403
406
// If preload is not enabled, we parse through each imports and remove any imports to pure CSS chunks
404
407
// as they are removed from the bundle
405
- if ( ! insertPreload ) {
408
+ if ( ! getInsertPreload ( this . environment ) ) {
406
409
const removedPureCssFiles = removedPureCssFilesCache . get ( config )
407
410
if ( removedPureCssFiles && removedPureCssFiles . size > 0 ) {
408
411
for ( const file in bundle ) {
0 commit comments