1+ const { getOptions } = require ( 'loader-utils' )
2+
13const stringifyRequest = require ( 'loader-utils/lib/stringifyRequest' )
2- const getDevlandFile = require ( './get-devland-file.js' )
4+ const getDevlandFile = require ( './get-devland-file' )
5+
36const autoImportData = getDevlandFile ( 'quasar/dist/transforms/auto-import.json' )
47const importTransformation = getDevlandFile ( 'quasar/dist/transforms/import-transformation.js' )
5-
6- const runtimePath = require . resolve ( './runtime.auto-import.js' )
8+ const autoImportRuntimePath = require . resolve ( './runtime.auto-import.js' )
79
810const compRegex = {
911 'kebab' : new RegExp ( autoImportData . regex . kebabComponents || autoImportData . regex . components , 'g' ) ,
@@ -19,11 +21,8 @@ function transform (itemArray) {
1921 . join ( `\n` )
2022}
2123
22- function extract ( content , ctx ) {
23- // Use webpack v5 getOptions or fallback to ctx.query for webpack v4
24- const { strategy } = ctx . getOptions ? ctx . getOptions ( ) : ctx . query
25-
26- let comp = content . match ( compRegex [ strategy ] )
24+ function extract ( content , ctx , autoImportCase ) {
25+ let comp = content . match ( compRegex [ autoImportCase ] )
2726 let dir = content . match ( dirRegex )
2827
2928 if ( comp === null && dir === null ) {
@@ -38,11 +37,11 @@ function extract (content, ctx) {
3837 comp = Array . from ( new Set ( comp ) )
3938
4039 // map comp names only if not pascal-case already
41- if ( strategy !== 'pascal' ) {
40+ if ( autoImportCase !== 'pascal' ) {
4241 comp = comp . map ( name => autoImportData . importName [ name ] )
4342 }
4443
45- if ( strategy === 'combined' ) {
44+ if ( autoImportCase === 'combined' ) {
4645 // could have been transformed QIcon and q-icon too,
4746 // so avoid duplicates
4847 comp = Array . from ( new Set ( comp ) )
@@ -64,7 +63,7 @@ function extract (content, ctx) {
6463 // messes up consistency of hashes between builds
6564 return `
6665${ importStatements }
67- import qInstall from ${ stringifyRequest ( ctx , runtimePath ) } ;
66+ import qInstall from ${ stringifyRequest ( ctx , autoImportRuntimePath ) } ;
6867${ installStatements }
6968`
7069}
@@ -73,17 +72,21 @@ module.exports = function (content, map) {
7372 let newContent = content
7473
7574 if ( ! this . resourceQuery ) {
76- const file = this . fs . readFileSync ( this . resource , 'utf-8' ) . toString ( )
77- const code = extract ( file , this )
75+ const opts = getOptions ( this )
76+
77+ if ( opts . isServerBuild !== true ) {
78+ const file = this . fs . readFileSync ( this . resource , 'utf-8' ) . toString ( )
79+ const code = extract ( file , this , opts . strategy )
7880
79- if ( code !== void 0 ) {
80- const index = this . mode === 'development'
81- ? content . indexOf ( '/* hot reload */' )
82- : - 1
81+ if ( code !== void 0 ) {
82+ const index = this . mode === 'development'
83+ ? content . indexOf ( '/* hot reload */' )
84+ : - 1
8385
84- newContent = index === - 1
85- ? content + code
86- : content . slice ( 0 , index ) + code + content . slice ( index )
86+ newContent = index === - 1
87+ ? content + code
88+ : content . slice ( 0 , index ) + code + content . slice ( index )
89+ }
8790 }
8891 }
8992
0 commit comments