Skip to content

Commit 855a4e2

Browse files
committed
build(react-vite): avoid starting bundler analyzing server in
1 parent 05a7371 commit 855a4e2

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

demo/react-vite/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"postinstall": "cd ../shared && npm ci",
99
"build": "vite build",
1010
"build:feature": "tsc -b && vite build",
11+
"build:analysis": "vite build --mode analysis",
1112
"lint": "eslint .",
1213
"preview": "vite preview"
1314
},

demo/react-vite/vite.config.ts

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,48 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
1010
// todo: why __dirname is available when installed @types/node? we didn't specify the type in tsconfig.json
1111
// todo: installing @types/node can fix the type issue for path and url, but it will also make __dirname works? which may be incorrect?
1212
// 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+
}
3355
}
34-
}
56+
})
3557
})

0 commit comments

Comments
 (0)