This commit is contained in:
2025-01-17 03:19:00 +08:00
parent 6d2bc0f2aa
commit b20a2d9849
25 changed files with 12546 additions and 229 deletions

View File

@@ -2,31 +2,62 @@ import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import copy from "rollup-plugin-copy";
import path from 'path';
import fs from 'fs';
function replaceKucTagsPlugin() {
return {
name: 'vite-plugin-replace-tags',
async load(id) {
if (id.endsWith('.vue')) {
const content = await fs.promises.readFile(id, 'utf-8');
return content
.replace(/<\/kuc-([a-zA-Z0-9-]+)(?![0-9-])>/g, (match, p1) => `</kuc-${p1}-1-18-0>`)
.replace(/<kuc-([a-zA-Z0-9-]+)(?![0-9-])([^>]*)>/g, (match, p1, p2) => `<kuc-${p1}-1-18-0${p2}>`);
}
}
};
}
// https://vite.dev/config/
export default defineConfig({
plugins: [
vue(),
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag.startsWith("kuc-"),
}
}
}),
copy({
targets: [
{ src: 'dist/index.html', dest: 'dist/src/html', rename: 'config.html' }
{ src: 'dist/index.html', dest: 'dist/src/html', rename: 'config.html' },
{ src: 'src/manifest.json', dest: 'dist/src' },
{ src: 'src/assets/*', dest: 'dist/src/image' },
{ src: 'src/css/*', dest: 'dist/src/css' },
],
hook: 'writeBundle' // 指定在何时复制文件
})
}),
replaceKucTagsPlugin()
],
build:{
rollupOptions:{
input:{
config:path.resolve(__dirname,'index.html'),
desktop:path.resolve(__dirname,'src/js/desktop.js'),
mobile:path.resolve(__dirname,'src/js/mobile.js'),
build: {
rollupOptions: {
input: {
config: path.resolve(__dirname, 'index.html'),
desktop: path.resolve(__dirname, 'src/js/desktop.ts'),
mobile: path.resolve(__dirname, 'src/js/mobile.ts'),
},
output:{
output: {
entryFileNames: (chunkInfo) => {
// console.log(chunkInfo);
return 'src/js/[name].js'; // 默认处理为 JS 文件
},
assetFileNames:'src/[ext]/[name].[ext]'
assetFileNames: (assetInfo) => {
if (assetInfo.names[0].endsWith('.css') && assetInfo.originalFileNames[0] === 'index.html') {
return 'src/css/config.css';
}
// 其他资源文件的默认处理
return 'src/[ext]/[name].[ext]';
},
}
}
}