@@ -13,6 +13,8 @@ import vueJsx from '@vitejs/plugin-vue-jsx';
13
13
import eslintPlugin from 'vite-plugin-eslint' ; //导入包
14
14
import vueSetupExtend from 'vite-plugin-vue-setup-extend-plus' ;
15
15
import autoImports from 'unplugin-auto-import/vite' ;
16
+ import { resolve } from 'path' ;
17
+ import autoprefixer from 'autoprefixer' ;
16
18
// import { VitePWA } from 'vite-plugin-pwa';
17
19
18
20
type CacheStrategy =
@@ -28,8 +30,6 @@ interface IgetCache {
28
30
cacheType ?: CacheStrategy ;
29
31
}
30
32
31
- const autoprefixer = require ( 'autoprefixer' ) ;
32
- const path = require ( 'path' ) ;
33
33
const getCache = ( { name, pattern, cacheDay = 7 , cacheType } : IgetCache ) => ( {
34
34
urlPattern : pattern ,
35
35
handler : cacheType || 'CacheFirst' ,
@@ -98,13 +98,13 @@ const config = ({ mode }) => {
98
98
] ,
99
99
build : {
100
100
target : 'es2015' ,
101
- outDir : path . resolve ( __dirname , 'dist' ) ,
101
+ outDir : resolve ( __dirname , 'dist' ) ,
102
102
assetsDir : 'assets' ,
103
103
assetsInlineLimit : 8192 ,
104
104
// sourcemap: !isProd,
105
105
emptyOutDir : true ,
106
106
rollupOptions : {
107
- input : path . resolve ( __dirname , 'index.html' ) ,
107
+ input : resolve ( __dirname , 'index.html' ) ,
108
108
output : {
109
109
chunkFileNames : 'js/[name].[hash].js' ,
110
110
entryFileNames : 'js/[name].[hash].js' ,
@@ -114,20 +114,32 @@ const config = ({ mode }) => {
114
114
envPrefix,
115
115
resolve : {
116
116
alias : [
117
- { find : / ^ @ \/ / , replacement : path . resolve ( __dirname , 'src' ) + '/' } ,
117
+ { find : / ^ @ \/ / , replacement : resolve ( __dirname , 'src' ) + '/' } ,
118
118
{ find : / ^ ~ / , replacement : '' } ,
119
119
{ find : / ^ v u e - i 1 8 n / , replacement : 'vue-i18n/dist/vue-i18n.cjs.js' } ,
120
120
] ,
121
121
extensions : [ '.ts' , '.tsx' , '.js' , '.mjs' , '.vue' , '.json' , '.less' , '.css' ] ,
122
122
} ,
123
123
css : {
124
124
postcss : {
125
- plugins : [ autoprefixer ] ,
125
+ plugins : [
126
+ autoprefixer ( {
127
+ // 自动添加前缀
128
+ overrideBrowserslist : [
129
+ 'Android 4.1' ,
130
+ 'iOS 7.1' ,
131
+ 'Chrome > 31' ,
132
+ 'ff > 31' ,
133
+ 'ie >= 8' ,
134
+ 'last 2 versions' , // 所有主流浏览器最近2个版本
135
+ ] ,
136
+ } ) ,
137
+ ] ,
126
138
} ,
127
139
preprocessorOptions : {
128
140
less : {
129
141
javascriptEnabled : true ,
130
- additionalData : `@import " ${ path . resolve ( __dirname , 'src/styles/variable.less' ) } ";` ,
142
+ additionalData : `@import ' ${ resolve ( __dirname , 'src/styles/variable.less' ) } ";` ,
131
143
} ,
132
144
} ,
133
145
} ,
0 commit comments