增加了 打包生成 菜单配置文件 .json

This commit is contained in:
hawk86104 2024-03-25 21:23:26 +08:00
parent f57df25ff4
commit d94e704489
5 changed files with 64 additions and 4 deletions

View File

@ -4,7 +4,7 @@
* @Autor: 地虎降天龙
* @Date: 2023-10-16 10:53:09
* @LastEditors: 地虎降天龙
* @LastEditTime: 2024-03-18 10:06:11
* @LastEditTime: 2024-03-25 15:37:42
*/
// import { resolve } from 'path';
import { join } from 'path';

View File

@ -4,9 +4,10 @@
* @Autor: 地虎降天龙
* @Date: 2023-10-16 10:53:09
* @LastEditors: 地虎降天龙
* @LastEditTime: 2024-03-05 08:47:57
* @LastEditTime: 2024-03-25 21:06:01
*/
import { defineBuildConfig } from '@fesjs/fes';
import { defineBuildConfig } from '@fesjs/fes'
import addExtraScriptPlugin from './src/common/addExtraScriptPlugin'
export default defineBuildConfig({
layout: {
@ -76,4 +77,9 @@ export default defineBuildConfig({
}
],
},
viteOption: {
plugins: [
addExtraScriptPlugin()
]
},
});

View File

@ -22,6 +22,7 @@
"@types/three": "0.161.1",
"@webank/eslint-config-webank": "1.3.1",
"cross-env": "^7.0.3",
"esm": "^3.2.25",
"vite-plugin-glsl": "0.2.2"
},
"dependencies": {

View File

@ -0,0 +1,52 @@
/*
* @Description:
* @Version: 1.668
* @Autor: 地虎降天龙
* @Date: 2024-03-25 15:39:04
* @LastEditors: 地虎降天龙
* @LastEditTime: 2024-03-25 21:18:49
*/
const path = require('path')
const fs = require('fs').promises
const glob = require('glob')
const getPluginsConfig = () => {
// console.log(__dirname)
// const modulePaths = glob.sync('/plugins/**/config.js', { eager: true, cwd: __dirname }); //../../src , sync: true
const configFiles = glob.sync('../plugins/*/config.js', { cwd: __dirname })
// 读取这些文件的内容并合并
const configs = {}
const require2 = require('esm')(module)
configFiles.forEach(async (file) => {
const config = require2(path.join(__dirname, file)).default
configs[config.name] = config
})
// console.log(configs);
return { configs, date: new Date().toLocaleString() }
}
// getPluginsConfig()
export default function addExtraScriptPlugin () {
return {
name: 'add-extra-script-plugin',
async generateBundle () {
async function writeToFile () {
try {
// 初始化要写入的文件内容
const pluginsConfig = getPluginsConfig()
const content = JSON.stringify(pluginsConfig)
// 写入文件
await fs.writeFile('dist/menu.json', content, 'utf8')
// console.log('menu.json written successfully.', pluginsConfig)
} catch (error) {
console.error('Error writing file:', error)
}
}
await writeToFile()
}
};
}

View File

@ -4,7 +4,7 @@
* @Autor: 地虎降天龙
* @Date: 2023-11-18 22:17:49
* @LastEditors: 地虎降天龙
* @LastEditTime: 2024-03-25 11:34:53
* @LastEditTime: 2024-03-25 21:17:24
-->
<template>
<div class="flex h-full">
@ -138,6 +138,7 @@ function filterObjects(obj: any, searchString: string) {
return result
}
let filteredData = ref(pluginsConfig)
watch(filterFixedInputValue, (newValue: any) => {
filteredData.value = filterObjects(pluginsConfig, newValue.toLocaleLowerCase())
if (!newValue) {