90 lines
2.1 KiB
JavaScript
90 lines
2.1 KiB
JavaScript
import {
|
||
defineConfig
|
||
} from 'vite';
|
||
import uni from "@dcloudio/vite-plugin-uni";
|
||
import AutoImport from 'unplugin-auto-import/vite';
|
||
import Components from 'unplugin-vue-components/vite';
|
||
|
||
export default defineConfig({
|
||
build: {
|
||
minify: 'terser',
|
||
// assetsInlineLimit: 0, // 禁止将图片转成 import
|
||
terserOptions: {
|
||
compress: {
|
||
drop_console: true,
|
||
},
|
||
},
|
||
},
|
||
plugins: [
|
||
uni(),
|
||
{
|
||
name: 'transform-assets',
|
||
enforce: 'pre', // 在 Vue 插件之前执行
|
||
transform(code, id) {
|
||
|
||
if (/\.(vue|js|ts|css|scss|json)$/.test(id)) {
|
||
let count = 0
|
||
const replacedCode = code.replace(
|
||
/@@:([^\s"'()<>]+?\.(png|jpe?g|gif|svg|webp))/g,
|
||
(match, path) => {
|
||
count++
|
||
return `https://guyu-1308826010.cos.ap-shanghai.myqcloud.com/${path}`
|
||
}
|
||
);
|
||
if (count > 0) {
|
||
console.log(id, `本次替换了 ${count} 个图片地址`)
|
||
}
|
||
// console.log(id)
|
||
return {
|
||
code: replacedCode,
|
||
map: null
|
||
}
|
||
}
|
||
},
|
||
},
|
||
// 自动导入 Vue 相关 API(如 ref, reactive)
|
||
AutoImport({
|
||
imports: ['vue',
|
||
{
|
||
'@dcloudio/uni-app': [
|
||
'onLoad', // 页面加载时触发
|
||
'onShow', // 页面显示时触发
|
||
'onHide', // 页面隐藏时触发
|
||
'onUnload', // 页面卸载时触发
|
||
],
|
||
},
|
||
{
|
||
'@/common/utils': [
|
||
'showToast', // 明确列出方法名(推荐)
|
||
'sleep',
|
||
],
|
||
}
|
||
,
|
||
{
|
||
'@/common/com': [
|
||
['com'], // 从 '@/common/index' 导入 yds 对象
|
||
],
|
||
}
|
||
],
|
||
}),
|
||
// 自动导入组件
|
||
Components({
|
||
dirs: [
|
||
'components/**/*',
|
||
], // 指定组件目录
|
||
extensions: ['vue'],
|
||
dts: true, // 生成类型声明文件(可选)
|
||
// resolvers: [
|
||
// (name) => {
|
||
// if (name === 'uni-popup') { // 匹配 kebab-case 名称
|
||
// return {
|
||
// importName: 'uni-popup', // 组件文件实际导出的名称
|
||
// path: '@/components/uni-popup/components/uni-popup/uni-popup.vue', // 文件路径
|
||
// kebabCase: true
|
||
// }
|
||
// }
|
||
// }
|
||
// ]
|
||
}),
|
||
]
|
||
}); |