1
+ const { getOptions } = require ( 'loader-utils' )
2
+
1
3
const stringifyRequest = require ( 'loader-utils/lib/stringifyRequest' )
2
- const getDevlandFile = require ( './get-devland-file.js' )
4
+ const getDevlandFile = require ( './get-devland-file' )
5
+
3
6
const autoImportData = getDevlandFile ( 'quasar/dist/transforms/auto-import.json' )
4
7
const 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' )
7
9
8
10
const compRegex = {
9
11
'kebab' : new RegExp ( autoImportData . regex . kebabComponents || autoImportData . regex . components , 'g' ) ,
@@ -19,11 +21,8 @@ function transform (itemArray) {
19
21
. join ( `\n` )
20
22
}
21
23
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 ] )
27
26
let dir = content . match ( dirRegex )
28
27
29
28
if ( comp === null && dir === null ) {
@@ -38,11 +37,11 @@ function extract (content, ctx) {
38
37
comp = Array . from ( new Set ( comp ) )
39
38
40
39
// map comp names only if not pascal-case already
41
- if ( strategy !== 'pascal' ) {
40
+ if ( autoImportCase !== 'pascal' ) {
42
41
comp = comp . map ( name => autoImportData . importName [ name ] )
43
42
}
44
43
45
- if ( strategy === 'combined' ) {
44
+ if ( autoImportCase === 'combined' ) {
46
45
// could have been transformed QIcon and q-icon too,
47
46
// so avoid duplicates
48
47
comp = Array . from ( new Set ( comp ) )
@@ -64,7 +63,7 @@ function extract (content, ctx) {
64
63
// messes up consistency of hashes between builds
65
64
return `
66
65
${ importStatements }
67
- import qInstall from ${ stringifyRequest ( ctx , runtimePath ) } ;
66
+ import qInstall from ${ stringifyRequest ( ctx , autoImportRuntimePath ) } ;
68
67
${ installStatements }
69
68
`
70
69
}
@@ -73,17 +72,21 @@ module.exports = function (content, map) {
73
72
let newContent = content
74
73
75
74
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 )
78
80
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
83
85
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
+ }
87
90
}
88
91
}
89
92
0 commit comments