@@ -408,25 +408,25 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
408
408
} ,
409
409
410
410
transform ( code , id , transformOpts ) {
411
- const shouldTransformFile = fileFilter ( id , 'transform' ) ;
412
- const isStringImportId = id . includes ( '?raw' ) ;
413
- if ( isVirtualId ( id ) || ! shouldTransformFile || isStringImportId ) {
414
- return null ;
415
- }
416
411
if (
417
412
id . includes ( '.vite/deps/' ) &&
418
413
code . slice ( 0 , 5000 ) . includes ( 'qwik' ) &&
419
414
/ i m p o r t [ ^ \n ] * q w i k [ ^ \n ] * \n / . test ( code )
420
415
) {
421
416
const relPath = rootDir && id . startsWith ( rootDir ) ? id . slice ( rootDir . length ) : id ;
422
417
throw new Error (
423
- `\n==============\n` +
424
- `This dependency was pre-bundled by Vite, but it seems to use Qwik, which needs processing by the optimizer.\n` +
425
- `Please add the original modulename to the "optimizeDeps.exclude" array in your Vite config: \n` +
426
- `${ relPath } \n` +
427
- `==============\n`
418
+ `\n\n ==============\n \n` +
419
+ `⚠️ IMPORTANT: This dependency was pre-bundled by Vite, but it seems to use Qwik, which needs processing by the optimizer.\n \n` +
420
+ `👉 Please add the original modulename to the "optimizeDeps.exclude" array in your Vite config\n` +
421
+ `👉 ${ relPath } \n \n` +
422
+ `==============\n\n `
428
423
) ;
429
424
}
425
+ const shouldTransformFile = fileFilter ( id , 'transform' ) ;
426
+ const isStringImportId = id . includes ( '?raw' ) ;
427
+ if ( isVirtualId ( id ) || ! shouldTransformFile || isStringImportId ) {
428
+ return null ;
429
+ }
430
430
431
431
return qwikPlugin . transform ( this , code , id , transformOpts ) ;
432
432
} ,
@@ -663,11 +663,30 @@ async function checkExternals() {
663
663
configResolved : ( config ) => {
664
664
rootDir = config . root ;
665
665
} ,
666
+ // Attempt to mark the Qwik dependencies as non-optimizeable
667
+ config : {
668
+ order : 'post' ,
669
+ async handler ( config ) {
670
+ const toExclude = [ ] ;
671
+ const externals = [ config . ssr ?. noExternal , config . environments ?. ssr ?. resolve ?. noExternal ]
672
+ . flat ( )
673
+ . filter ( ( t ) => typeof t === 'string' ) ;
674
+ const optimizeDepsExclude = config . optimizeDeps ?. exclude ?? [ ] ;
675
+ for ( const dep of externals ) {
676
+ if ( ! optimizeDepsExclude . includes ( dep ) ) {
677
+ if ( await isQwikDep ( dep , config . root || process . cwd ( ) ) ) {
678
+ toExclude . push ( dep ) ;
679
+ }
680
+ }
681
+ }
682
+ return { optimizeDeps : { exclude : toExclude } } ;
683
+ } ,
684
+ } ,
666
685
// We check all SSR build lookups for external Qwik deps
667
686
resolveId : {
668
687
order : 'pre' ,
669
688
async handler ( source , importer , options ) {
670
- if ( ! options . ssr || / ^ ( [ . / ] | n o d e : | [ ^ a - z ] ) / . test ( source ) || seen . has ( source ) ) {
689
+ if ( ! options . ssr || / ^ ( [ . / ] | n o d e : | [ ^ a - z @ ] ) / i . test ( source ) || seen . has ( source ) ) {
671
690
return ;
672
691
}
673
692
const packageName = (
@@ -679,22 +698,27 @@ async function checkExternals() {
679
698
// technically we should check for each importer, but this is ok
680
699
seen . add ( source ) ;
681
700
seen . add ( packageName ) ;
682
- const result = await this . resolve ( packageName , importer , { ...options , skipSelf : true } ) ;
683
- if ( result ?. external ) {
684
- // Qwik deps should not be external
685
- if ( await isQwikDep ( packageName , importer ? path . dirname ( importer ) : rootDir ) ) {
686
- // TODO link to docs
687
- throw new Error (
688
- `\n==============\n` +
689
- `${ packageName } is being treated as an external dependency, but it should be included in the server bundle, because it uses Qwik and it needs to be processed by the optimizer.\n` +
690
- `Please add the package to "ssr.noExternal[]" as well as "optimizeDeps.exclude[]" in the Vite config. \n` +
691
- `==============\n`
692
- ) ;
701
+ try {
702
+ const result = await this . resolve ( packageName , importer , { ...options , skipSelf : true } ) ;
703
+ if ( result ?. external ) {
704
+ // Qwik deps should not be external
705
+ if ( await isQwikDep ( packageName , importer ? path . dirname ( importer ) : rootDir ) ) {
706
+ // TODO link to docs
707
+ throw new Error (
708
+ `\n==============\n` +
709
+ `${ packageName } is being treated as an external dependency, but it should be included in the server bundle, because it uses Qwik and it needs to be processed by the optimizer.\n` +
710
+ `Please add the package to "ssr.noExternal[]" as well as "optimizeDeps.exclude[]" in the Vite config. \n` +
711
+ `==============\n`
712
+ ) ;
713
+ }
693
714
}
694
- }
695
- if ( packageName === source ) {
696
- // We already resolved it, so return that result
697
- return result ;
715
+ if ( packageName === source ) {
716
+ // We already resolved it, so return that result
717
+ return result ;
718
+ }
719
+ } catch {
720
+ /* ignore, let vite figure it out */
721
+ return ;
698
722
}
699
723
} ,
700
724
} ,
0 commit comments