perf(plugin-md-power): optimize package build

This commit is contained in:
pengzhanbo 2024-07-19 10:20:36 +08:00
parent d11bf77403
commit 8888d9fe5c
19 changed files with 66 additions and 32 deletions

View File

@ -31,10 +31,10 @@
"lib"
],
"scripts": {
"build": "pnpm run copy && pnpm run ts",
"clean": "rimraf --glob ./lib ./*.tsbuildinfo",
"build": "pnpm copy && pnpm tsup",
"clean": "rimraf --glob ./lib",
"copy": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png}\" lib",
"ts": "tsc -b tsconfig.build.json"
"tsup": "tsup --config tsup.config.ts"
},
"peerDependencies": {
"@iconify/json": "^2",

View File

@ -1,6 +1,6 @@
<script setup lang="ts">
import { computed } from 'vue'
import type { CodeSandboxTokenMeta } from '../../shared/codeSandbox.js'
import type { CodeSandboxTokenMeta } from '../../shared/index.js'
const props = defineProps<CodeSandboxTokenMeta>()

View File

@ -1,6 +1,6 @@
<script setup lang="ts">
import { onMounted, toRefs } from 'vue'
import type { PDFTokenMeta } from '../../shared/pdf.js'
import type { PDFTokenMeta } from '../../shared/index.js'
import { useSize } from '../composables/size.js'
import { usePDF } from '../composables/pdf.js'

View File

@ -2,7 +2,7 @@
import { computed, ref, shallowRef } from 'vue'
import { onClickOutside, useMediaQuery } from '@vueuse/core'
import { usePageFrontmatter } from 'vuepress/client'
import type { PlotOptions } from '../../shared/plot.js'
import type { PlotOptions } from '../../shared/index.js'
import { pluginOptions } from '../options.js'
const props = defineProps<Omit<PlotOptions, 'tag'>>()

View File

@ -1,6 +1,6 @@
<script setup lang="ts">
import { computed, getCurrentInstance, ref } from 'vue'
import type { ReplitTokenMeta } from '../../shared/replit.js'
import type { ReplitTokenMeta } from '../../shared/index.js'
import Loading from './Loading.vue'
const props = defineProps<ReplitTokenMeta>()

View File

@ -13,7 +13,7 @@
import { ensureEndingSlash, isLinkHttp } from 'vuepress/shared'
import { withBase } from 'vuepress/client'
import type { PDFEmbedType, PDFTokenMeta } from '../../shared/pdf.js'
import type { PDFEmbedType, PDFTokenMeta } from '../../shared/index.js'
import { pluginOptions } from '../options.js'
import { checkIsMobile, checkIsSafari, checkIsiPad } from '../utils/is.js'

View File

@ -15,7 +15,7 @@ import type { MaybeRef } from '@vueuse/core'
import { useEventListener } from '@vueuse/core'
import type { Ref, ShallowRef, ToRefs } from 'vue'
import { computed, isRef, onMounted, ref, shallowRef, toValue, watch } from 'vue'
import type { SizeOptions } from '../../shared/size.js'
import type { SizeOptions } from '../../shared/index.js'
export interface SizeInfo<T extends HTMLElement> {
el: ShallowRef<T | undefined>

View File

@ -6,7 +6,7 @@
import type { PluginWithOptions } from 'markdown-it'
import { resolveAttrs } from '../utils/resolveAttrs.js'
import { parseRect } from '../utils/parseRect.js'
import type { CodeSandboxTokenMeta } from '../../shared/codeSandbox.js'
import type { CodeSandboxTokenMeta } from '../../shared/index.js'
import { createRuleBlock } from '../utils/createRuleBlock.js'
export const codeSandboxPlugin: PluginWithOptions<never> = (md) => {

View File

@ -6,7 +6,7 @@
import type { PluginWithOptions } from 'markdown-it'
import { resolveAttrs } from '../utils/resolveAttrs.js'
import { parseRect } from '../utils/parseRect.js'
import type { CodepenTokenMeta } from '../../shared/codepen.js'
import type { CodepenTokenMeta } from '../../shared/index.js'
import { createRuleBlock } from '../utils/createRuleBlock.js'
const CODEPEN_LINK = 'https://codepen.io/'

View File

@ -4,7 +4,7 @@ import { getIconContentCSS, getIconData } from '@iconify/utils'
import { fs, logger } from 'vuepress/utils'
import { isPackageExists } from 'local-pkg'
import { customAlphabet } from 'nanoid'
import type { IconsOptions } from '../../../shared/icons.js'
import type { IconsOptions } from '../../../shared/index.js'
import { interopDefault } from '../../utils/package.js'
import { parseRect } from '../../utils/parseRect.js'

View File

@ -5,7 +5,7 @@
import type { PluginWithOptions } from 'markdown-it'
import { resolveAttrs } from '../utils/resolveAttrs.js'
import { parseRect } from '../utils/parseRect.js'
import type { JSFiddleTokenMeta } from '../../shared/jsfiddle.js'
import type { JSFiddleTokenMeta } from '../../shared/index.js'
import { createRuleBlock } from '../utils/createRuleBlock.js'
export const jsfiddlePlugin: PluginWithOptions<never> = (md) => {

View File

@ -3,7 +3,7 @@ import container from 'markdown-it-container'
import type Token from 'markdown-it/lib/token.mjs'
import type { App } from 'vuepress/core'
import { fs, getDirname, path } from 'vuepress/utils'
import type { ReplEditorData, ReplOptions } from '../../shared/repl.js'
import type { ReplEditorData, ReplOptions } from '../../shared/index.js'
const RE_INFO = /^(#editable)?(.*)$/

View File

@ -5,7 +5,7 @@
*/
import { path } from 'vuepress/utils'
import type { PluginWithOptions } from 'markdown-it'
import type { PDFTokenMeta } from '../../shared/pdf.js'
import type { PDFTokenMeta } from '../../shared/index.js'
import { resolveAttrs } from '../utils/resolveAttrs.js'
import { parseRect } from '../utils/parseRect.js'
import { createRuleBlock } from '../utils/createRuleBlock.js'

View File

@ -6,7 +6,7 @@
import type { PluginWithOptions } from 'markdown-it'
import { resolveAttrs } from '../utils/resolveAttrs.js'
import { parseRect } from '../utils/parseRect.js'
import type { ReplitTokenMeta } from '../../shared/replit.js'
import type { ReplitTokenMeta } from '../../shared/index.js'
import { createRuleBlock } from '../utils/createRuleBlock.js'
export const replitPlugin: PluginWithOptions<never> = (md) => {

View File

@ -6,7 +6,7 @@
*/
import { URLSearchParams } from 'node:url'
import type { PluginWithOptions } from 'markdown-it'
import type { BilibiliTokenMeta } from '../../../shared/video.js'
import type { BilibiliTokenMeta } from '../../../shared/index.js'
import { resolveAttrs } from '../../utils/resolveAttrs.js'
import { parseRect } from '../../utils/parseRect.js'
import { timeToSeconds } from '../../utils/timeToSeconds.js'

View File

@ -3,7 +3,7 @@
*/
import { URLSearchParams } from 'node:url'
import type { PluginWithOptions } from 'markdown-it'
import type { YoutubeTokenMeta } from '../../../shared/video.js'
import type { YoutubeTokenMeta } from '../../../shared/index.js'
import { resolveAttrs } from '../../utils/resolveAttrs.js'
import { parseRect } from '../../utils/parseRect.js'
import { timeToSeconds } from '../../utils/timeToSeconds.js'

View File

@ -4,8 +4,11 @@ export * from './icons.js'
export * from './video.js'
export * from './codepen.js'
export * from './codeSandbox.js'
export * from './repl.js'
export * from './replit.js'
export * from './jsfiddle.js'
export * from './plot.js'
export * from './plugin.js'
export * from './size.js'

View File

@ -1,14 +0,0 @@
{
"extends": "../tsconfig.build.json",
"compilerOptions": {
"rootDir": "./src",
"types": [
"vuepress/client-types",
"vite/client",
"webpack-env"
],
"outDir": "./lib"
},
"files": [],
"include": ["./src"]
}

View File

@ -0,0 +1,45 @@
import { type Options, defineConfig } from 'tsup'
const config = [
{ dir: 'composables', files: ['codeRepl.ts', 'pdf.ts', 'rustRepl.ts', 'size.ts'] },
{ dir: 'utils', files: ['http.ts', 'is.ts', 'link.ts', 'sleep.ts'] },
{ dir: '', files: ['index.ts', 'options.ts'] },
]
const clientExternal = [
/composables\/.*\.js$/,
/utils\/.*\.js$/,
/.*\/options\.js$/,
/shared\/index\.js$/,
]
export default defineConfig(() => {
const DEFAULT_OPTIONS: Options = {
dts: true,
sourcemap: false,
splitting: false,
format: 'esm',
}
return [
// shared
{
...DEFAULT_OPTIONS,
entry: ['./src/shared/index.ts'],
outDir: './lib/shared',
},
// node
{
...DEFAULT_OPTIONS,
entry: ['./src/node/index.ts'],
outDir: './lib/node',
target: 'node18',
},
// client
...config.map(({ dir, files }) => ({
...DEFAULT_OPTIONS,
entry: files.map(file => `./src/client/${dir}/${file}`),
outDir: `./lib/client/${dir}`,
external: clientExternal,
}) as Options),
]
})