@@ -10,26 +10,48 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
10
// todo: why __dirname is available when installed @types /node? we didn't specify the type in tsconfig.json
11
11
// todo: installing @types /node can fix the type issue for path and url, but it will also make __dirname works? which may be incorrect?
12
12
// todo: remove @types /node and check all the questions
13
- export default defineConfig ( {
14
- base : './' ,
15
- plugins : [ tsconfigPaths ( ) , react ( ) , analyzer ( { openAnalyzer : false } ) ] ,
16
- css : {
17
- modules : {
18
- generateScopedName : '[name]__[local]__[hash:base64:5]'
19
- }
20
- } ,
21
- server : {
22
- fs : {
23
- allow : [
24
- path . resolve ( __dirname , '../shared' ) ,
25
- path . resolve ( __dirname , './' )
26
- ] // or path.resolve(__dirname, '../shared')
27
- }
28
- } ,
29
- resolve : {
30
- alias : {
31
- '@shared' : path . resolve ( __dirname , '../shared' ) ,
32
- src : path . resolve ( __dirname , './src' )
13
+ const productionConfig = {
14
+ plugins : [ ]
15
+ }
16
+ const developmentConfig = {
17
+ plugins : [ ]
18
+ }
19
+ const analysisConfig = {
20
+ plugins : [ analyzer ( { openAnalyzer : false } ) ]
21
+ }
22
+ function getExtraConfig ( mode : string ) {
23
+ return (
24
+ {
25
+ development : developmentConfig ,
26
+ production : productionConfig ,
27
+ analysis : analysisConfig
28
+ } [ mode ] || productionConfig
29
+ )
30
+ }
31
+
32
+ export default defineConfig ( ( { mode} ) => {
33
+ const extraConfig = getExtraConfig ( mode )
34
+ return ( {
35
+ base : './' ,
36
+ plugins : [ tsconfigPaths ( ) , react ( ) , ...extraConfig . plugins ] ,
37
+ css : {
38
+ modules : {
39
+ generateScopedName : '[name]__[local]__[hash:base64:5]'
40
+ }
41
+ } ,
42
+ server : {
43
+ fs : {
44
+ allow : [
45
+ path . resolve ( __dirname , '../shared' ) ,
46
+ path . resolve ( __dirname , './' )
47
+ ] // or path.resolve(__dirname, '../shared')
48
+ }
49
+ } ,
50
+ resolve : {
51
+ alias : {
52
+ '@shared' : path . resolve ( __dirname , '../shared' ) ,
53
+ src : path . resolve ( __dirname , './src' )
54
+ }
33
55
}
34
- }
56
+ } )
35
57
} )
0 commit comments