Skip to content

Commit dc57926

Browse files
committed
fix: make vite plugins not work on preview
1 parent 3f8653f commit dc57926

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

vite.config.ts

+20-18
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Components from 'unplugin-vue-components/vite'
99
import { defineConfig } from 'vite'
1010
import vueSetupExtend from 'vite-plugin-vue-setup-extend'
1111

12-
const isProduction = process.env.NODE_ENV === 'production'
12+
const isPreview = process.env.NODE_ENV === 'production'
1313

1414
// https://vitejs.dev/config/
1515
export default defineConfig({
@@ -21,25 +21,27 @@ export default defineConfig({
2121
plugins: [
2222
AutoImportTypes(),
2323
PiniaAutoRefs(),
24-
AutoImport({
25-
dts: 'src/auto-imports.d.ts', // 可以自定义文件生成的位置,默认是根目录下
26-
imports: [
27-
'vue',
28-
'vue-router',
29-
'pinia',
30-
{
31-
'@/helper/pinia-auto-refs': ['useStore'],
24+
// 解决 preview 时 auto-imports 文件被修改的问题
25+
!isPreview &&
26+
AutoImport({
27+
dts: 'src/auto-imports.d.ts', // 可以自定义文件生成的位置,默认是根目录下
28+
imports: [
29+
'vue',
30+
'vue-router',
31+
'pinia',
32+
{
33+
'@/helper/pinia-auto-refs': ['useStore'],
34+
},
35+
],
36+
eslintrc: {
37+
enabled: true, // Default `false`
38+
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
39+
globalsPropValue: 'readonly', // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
3240
},
33-
],
34-
eslintrc: {
35-
enabled: true, // Default `false`
36-
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
37-
globalsPropValue: 'readonly', // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
38-
},
39-
resolvers: [ElementPlusResolver()],
40-
}),
41+
resolvers: [ElementPlusResolver()],
42+
}),
4143
// 解决 preview 时 components 文件被修改的问题
42-
!isProduction &&
44+
!isPreview &&
4345
Components({
4446
// 指定组件位置,默认是src/components
4547
dirs: ['src/components'],

0 commit comments

Comments
 (0)