91 lines
3.8 KiB
TypeScript
91 lines
3.8 KiB
TypeScript
import { defineConfig } from 'vite';
|
||
import vue from '@vitejs/plugin-vue';
|
||
import { resolve } from 'path';
|
||
import vueJsx from '@vitejs/plugin-vue-jsx';
|
||
import postcssPluginPx2rem from 'postcss-plugin-px2rem';
|
||
import resolveExternalsPlugin from 'vite-plugin-resolve-externals';
|
||
|
||
function pathResolve(dir: string) {
|
||
return resolve(process.cwd(), '.', dir);
|
||
}
|
||
|
||
const px2remOptions = {
|
||
remUnit: 14,
|
||
rootValue: 17, //换算基数, 默认100 ,也就是1440px ,这样的话把根标签的字体规定为1rem为50px,这样就可以从设计稿上量出多少个px直接在代码中写多少px了
|
||
unitPrecision: 5, //允许REM单位增长到的十进制数字,其实就是精度控制
|
||
// propWhiteList: [], // 默认值是一个空数组,这意味着禁用白名单并启用所有属性。
|
||
// propBlackList: [], // 黑名单
|
||
// exclude:false, //默认false,可以(reg)利用正则表达式排除某些文件夹的方法,例如/(node_module)/ 。如果想把前端UI框架内的px也转换成rem,请把此属性设为默认值
|
||
// selectorBlackList: [], //要忽略并保留为px的选择器
|
||
// ignoreIdentifier: false, //(boolean/string)忽略单个属性的方法,启用ignoreidentifier后,replace将自动设置为true。
|
||
// replace: true, // (布尔值)替换包含REM的规则,而不是添加回退。
|
||
mediaQuery: false, //(布尔值)允许在媒体查询中转换px
|
||
minPixelValue: 2, //设置要替换的最小像素值(3px会被转rem)。 默认 0
|
||
};
|
||
// https://vitejs.dev/config/
|
||
export default defineConfig({
|
||
plugins: [
|
||
vue(),
|
||
resolveExternalsPlugin({
|
||
AMap: 'AMap',
|
||
}),
|
||
vueJsx(),
|
||
],
|
||
css: {
|
||
preprocessorOptions: {
|
||
less: {
|
||
javascriptEnabled: true,
|
||
},
|
||
},
|
||
postcss: {
|
||
plugins: [postcssPluginPx2rem(px2remOptions)],
|
||
},
|
||
},
|
||
resolve: {
|
||
alias: [
|
||
{
|
||
find: /\/@\//,
|
||
replacement: pathResolve('src') + '/',
|
||
},
|
||
],
|
||
extensions: ['.js', '.ts', '.mjs', '.vue', '.json', '.less', '.css'],
|
||
},
|
||
server: {
|
||
host: true,
|
||
https: false,
|
||
},
|
||
optimizeDeps: {
|
||
esbuildOptions: {
|
||
target: 'es2020',
|
||
},
|
||
// @iconify/iconify: The dependency is dynamically and virtually loaded by @purge-icons/generated, so it needs to be specified explicitly
|
||
include: ['lodash-es', 'ant-design-vue/es/locale/zh_CN', 'ant-design-vue/es/locale/en_US'],
|
||
},
|
||
build: {
|
||
sourcemap: false,
|
||
// rollupOptions: {
|
||
// output: {
|
||
// //入口文件输出配置
|
||
// entryFileNames: `assets/js/[name]-[hash].js`,
|
||
// //代码分割后的文件输出配置
|
||
// chunkFileNames: `assets/js/[name]-[hash].js`,
|
||
// //静态资源输出配置
|
||
// assetFileNames(assetInfo) {
|
||
// //css文件单独输出到css文件夹
|
||
// if (assetInfo.name.endsWith('.css')) {
|
||
// return `assets/css/[name]-[hash].css`;
|
||
// }
|
||
// //图片文件单独输出到img文件夹
|
||
// else if (['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp'].some((ext) => assetInfo.name.endsWith(ext))) {
|
||
// return `assets/img/[name]-[hash].[ext]`;
|
||
// }
|
||
// //其他资源输出到assets文件夹
|
||
// else {
|
||
// return `assets/[name]-[hash].[ext]`;
|
||
// }
|
||
// },
|
||
// },
|
||
// },
|
||
},
|
||
});
|