开发中途存档
This commit is contained in:
1 parent
a2de23a789
commit
a80575ef5e
19 files changed
+1998
-91
No files matched your search
+35
-1
@@ -1,8 +1,42 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import type { Plugin } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import { mkdirSync, readdirSync, writeFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
|
||||
function presetManifestPlugin(): Plugin {
|
||||
let presetDirectory = ''
|
||||
const updateManifest = () => {
|
||||
if (!presetDirectory) return
|
||||
mkdirSync(presetDirectory, { recursive: true })
|
||||
const presets = readdirSync(presetDirectory)
|
||||
.filter((file) => file.toLowerCase().endsWith('.json') && file !== 'index.json')
|
||||
.sort((a, b) => a.localeCompare(b, 'zh-CN'))
|
||||
.map((file) => ({ name: file.replace(/\.json$/i, ''), file }))
|
||||
writeFileSync(resolve(presetDirectory, 'index.json'), `${JSON.stringify(presets, null, 2)}\n`)
|
||||
}
|
||||
return {
|
||||
name: 'spine-particle-preset-manifest',
|
||||
configResolved(config) {
|
||||
presetDirectory = resolve(config.root, 'public/Preset')
|
||||
updateManifest()
|
||||
},
|
||||
buildStart() {
|
||||
updateManifest()
|
||||
},
|
||||
configureServer(server) {
|
||||
server.watcher.add(presetDirectory)
|
||||
const refresh = (file: string) => {
|
||||
if (file.startsWith(presetDirectory) && file.toLowerCase().endsWith('.json')) updateManifest()
|
||||
}
|
||||
server.watcher.on('add', refresh)
|
||||
server.watcher.on('unlink', refresh)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
plugins: [vue(), presetManifestPlugin()],
|
||||
server: {
|
||||
port: 5173,
|
||||
host: true,
|
||||
|
||||
Reference in new issue
Block a user