From 6fd8d0fe169f7a11ec1406a2ece5d81217bf365f Mon Sep 17 00:00:00 2001 From: mayinrain <624899618@qq.com> Date: Tue, 2 Apr 2024 16:36:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?upd:=20=E8=A7=A3=E5=86=B3=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E6=89=93=E5=8C=85=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/.vitepress/config.js | 15 +- .../custom/components/componentDoc.vue | 30 ++-- .../.vitepress/custom/components/constants.js | 42 +++++ .../custom/components/exampleRepl.vue | 154 ++++++++---------- .../custom/components/playground.js | 40 +++-- docs/.vitepress/scripts/genComponentDoc.js | 20 ++- docs/.vitepress/scripts/generate-doc.js | 3 + docs/package.json | 3 + package.json | 11 +- scripts/generate-doc.js | 5 - 10 files changed, 180 insertions(+), 143 deletions(-) create mode 100644 docs/.vitepress/custom/components/constants.js create mode 100644 docs/.vitepress/scripts/generate-doc.js create mode 100644 docs/package.json delete mode 100644 scripts/generate-doc.js diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index 146aeb6..dc6e658 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -2,11 +2,9 @@ import { defineConfig } from 'vitepress'; import vueJsx from '@vitejs/plugin-vue-jsx'; -const path = require('path'); +import path from 'path'; -const { - genComponentDoc -} = require('./scripts/genComponentDoc'); +import { genComponentDoc } from './scripts/genComponentDoc.js'; genComponentDoc(); const ssrTransformCustomDir = () => ({ @@ -30,13 +28,12 @@ export default defineConfig({ ignored: ['**/docs/.vueepress/components/**'] } }, - // optimizeDeps: { - // exclude: ['@vue/repl'] - // }, + optimizeDeps: { + exclude: ['@vue/repl'] + }, ssr: { // lodash-es 模块是 esm,ssr 渲染的时候编译成 cjs 的引入方式,会引发 nodejs 的模块加载异常错误 - noExternal: ['lodash-es', '@fesjs/fes-design', '@fesjs/fes-design/icon'], - // external: ['@vue/repl'] + noExternal: ['lodash-es', '@fesjs/fes-design', '@fesjs/fes-design/icon', '@vue/repl'] }, resolve: { extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'], diff --git a/docs/.vitepress/custom/components/componentDoc.vue b/docs/.vitepress/custom/components/componentDoc.vue index c5b1526..07ed8de 100644 --- a/docs/.vitepress/custom/components/componentDoc.vue +++ b/docs/.vitepress/custom/components/componentDoc.vue @@ -5,7 +5,7 @@
-
+
{{visibleCode ? '收起代码' : '查看代码'}} @@ -17,31 +17,31 @@ +`; + +export const FES_DESIGN_SETUP = ` +// 请谨慎修改内容!!! +import { getCurrentInstance } from 'vue'; +import FesDesign from '@fesjs/fes-design'; +import * as Icons from '@fesjs/fes-design/icon'; +export function loadStyle() { + const hasLinks = document.querySelectorAll('link'); + for(let l of hasLinks) { + if (/fes-design.min.css/.test(l.href)) return; + } + + const link = document.createElement('link') + link.rel = 'stylesheet' + link.href = 'https://registry.npmmirror.com/@fesjs/fes-design/latest/files/dist/fes-design.min.css'; + document.head.appendChild(link) + const twcsslink = document.createElement('link') + twcsslink.rel = 'stylesheet' + twcsslink.href = 'https://cdn.jsdelivr.net/npm/@fesjs/traction-widget/dist/traction-widget.min.css'; + document.head.appendChild(twcsslink) +} + +export function setupFesDesign() { + loadStyle(); + const instance = getCurrentInstance() + instance.appContext.app.use(FesDesign); + Object.keys(Icons).forEach((iconName) => { + instance.appContext.app.component(iconName, Icons[iconName]); + }); +} +`; diff --git a/docs/.vitepress/custom/components/exampleRepl.vue b/docs/.vitepress/custom/components/exampleRepl.vue index fb865f0..8415911 100644 --- a/docs/.vitepress/custom/components/exampleRepl.vue +++ b/docs/.vitepress/custom/components/exampleRepl.vue @@ -1,110 +1,96 @@ - - diff --git a/docs/.vitepress/custom/components/playground.js b/docs/.vitepress/custom/components/playground.js index 2411581..a09f9d3 100644 --- a/docs/.vitepress/custom/components/playground.js +++ b/docs/.vitepress/custom/components/playground.js @@ -1,20 +1,26 @@ -import { createVNode, render } from 'vue' -import ExampleRepl from './exampleRepl.vue' +import { createVNode, defineAsyncComponent, render } from 'vue'; -let vm -export default function playground (codeName) { - console.log('codeName', codeName) - if (vm) { - vm.component.exposed.handleShow(true) - vm.component.props.codeName = codeName - return vm - } - const container = document.createElement('div') - vm = createVNode(ExampleRepl, { - codeName - }) - render(vm, container) +const AsyncExampleRepl = defineAsyncComponent({ + loader: () => import('./exampleRepl.vue'), +}); - document.body.appendChild(container) - return vm +let vm; +export default function playground({ codeName, codeSrc }) { + if (vm) { + const exampleReplComponent = vm.component.subTree.component; + exampleReplComponent.props.codeName = codeName; + exampleReplComponent.props.codeSrc = codeSrc; + exampleReplComponent.exposed.handleShow(true); + return vm; + } + const container = document.createElement('div'); + vm = createVNode(AsyncExampleRepl, { + codeName, + codeSrc, + }); + + render(vm, container); + + document.body.appendChild(container); + return vm; } diff --git a/docs/.vitepress/scripts/genComponentDoc.js b/docs/.vitepress/scripts/genComponentDoc.js index 5020517..55a0988 100644 --- a/docs/.vitepress/scripts/genComponentDoc.js +++ b/docs/.vitepress/scripts/genComponentDoc.js @@ -1,8 +1,8 @@ -const path = require('path'); -const fs = require('fs'); -const fse = require('fs-extra'); -const shiki = require('shiki'); -const cheapWatch = require('cheap-watch'); +import path from 'path'; +import fs from 'fs'; +import fse from 'fs-extra'; +import shiki from 'shiki'; +import cheapWatch from 'cheap-watch'; const SCRIPT_TEMPLATE = `