mirror of https://github.com/halo-dev/halo
feat: add ui-plugin-bundler-kit package (#4916)
#### What type of PR is this? /area console /kind feature #### What this PR does / why we need it: 添加 `@halo-dev/ui-plugin-bundler-kit` 包,用于向插件提供统一的 Vite 构建配置。 最终用法: ```bash pnpm install @halo-dev/ui-plugin-bundler-kit -D ``` vite.config.ts ```ts import { HaloUIPluginBundlerKit } from "@halo-dev/ui-plugin-bundler-kit"; export default defineConfig({ plugins: [ Vue(), Icons({ compiler: "vue3" }), HaloUIPluginBundlerKit(), ], resolve: { alias: { "@": fileURLToPath(new URL("./src", import.meta.url)), }, }, }); ``` #### Which issue(s) this PR fixes: Fixes #4912 #### Special notes for your reviewer: 测试方式: 1. 在任意支持 UI 扩展的插件中添加此包:`pnpm install path/to/halo/console/packages/ui-plugin-bundler-kit` 2. 构建插件,检查 UI 相关的构建产物以及功能是否正常。 #### Does this PR introduce a user-facing change? ```release-note 添加 `@halo-dev/ui-plugin-bundler-kit` 包,用于向插件提供统一的构建配置。 ```pull/4878/head^2
parent
91affebdd1
commit
927398b6bd
|
@ -0,0 +1,2 @@
|
|||
dist/*
|
||||
node_modules/*
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
extends: ["../../.eslintrc.cjs"],
|
||||
};
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
plugins: ["../../prettier.config.js"],
|
||||
};
|
|
@ -0,0 +1,12 @@
|
|||
import { defineBuildConfig } from "unbuild";
|
||||
|
||||
export default defineBuildConfig({
|
||||
entries: ["src/index"],
|
||||
externals: ["vite"],
|
||||
clean: true,
|
||||
declaration: true,
|
||||
rollup: {
|
||||
emitCJS: true,
|
||||
inlineDependencies: true,
|
||||
},
|
||||
});
|
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"name": "@halo-dev/ui-plugin-bundler-kit",
|
||||
"version": "1.0.0",
|
||||
"homepage": "https://github.com/halo-dev/halo/tree/main/console/packages/ui-plugin-bundler-kit#readme",
|
||||
"bugs": {
|
||||
"url": "https://github.com/halo-dev/halo/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/halo-dev/halo.git",
|
||||
"directory": "console/packages/ui-plugin-bundler-kit"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"author": "@halo-dev",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "unbuild --stub",
|
||||
"prepublishOnly": "pnpm run build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@halo-dev/api-client": "workspace:*",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"js-yaml": "^4.1.0",
|
||||
"unbuild": "^0.7.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vite": "^4.0.0 || ^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.0.0 || >=20.0.0"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
import { Plugin } from "vite";
|
||||
import yaml from "js-yaml";
|
||||
import type { Plugin as HaloPlugin } from "@halo-dev/api-client";
|
||||
import fs from "fs";
|
||||
|
||||
export function HaloUIPluginBundlerKit(): Plugin {
|
||||
return {
|
||||
name: "halo-ui-plugin-bundler-kit",
|
||||
config(config, env) {
|
||||
const isProduction = env.mode === "production";
|
||||
|
||||
// fixme: allow user to config outDir
|
||||
const outDir = isProduction
|
||||
? "../src/main/resources/console"
|
||||
: "../build/resources/main/console";
|
||||
|
||||
// fixme: allow user to config manifest path
|
||||
const manifest = yaml.load(
|
||||
fs.readFileSync("../src/main/resources/plugin.yaml", "utf8")
|
||||
) as HaloPlugin;
|
||||
|
||||
return {
|
||||
...config,
|
||||
define: {
|
||||
"process.env": process.env,
|
||||
},
|
||||
build: {
|
||||
outDir,
|
||||
emptyOutDir: true,
|
||||
lib: {
|
||||
entry: "src/index.ts",
|
||||
name: manifest.metadata.name,
|
||||
formats: ["iife"],
|
||||
fileName: () => "main.js",
|
||||
},
|
||||
rollupOptions: {
|
||||
external: [
|
||||
"vue",
|
||||
"vue-router",
|
||||
"@vueuse/core",
|
||||
"@vueuse/components",
|
||||
"@vueuse/router",
|
||||
"@halo-dev/shared",
|
||||
"@halo-dev/components",
|
||||
],
|
||||
output: {
|
||||
globals: {
|
||||
vue: "Vue",
|
||||
"vue-router": "VueRouter",
|
||||
"@vueuse/core": "VueUse",
|
||||
"@vueuse/components": "VueUse",
|
||||
"@vueuse/router": "VueUse",
|
||||
"@halo-dev/console-shared": "HaloConsoleShared",
|
||||
"@halo-dev/components": "HaloComponents",
|
||||
},
|
||||
extend: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"include": ["src"],
|
||||
"exclude": ["**/*.spec.ts"],
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"target": "ES2020",
|
||||
"module": "ES2020",
|
||||
"moduleResolution": "node",
|
||||
"strict": true,
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"noImplicitOverride": true,
|
||||
"noUnusedLocals": true,
|
||||
"esModuleInterop": true,
|
||||
"baseUrl": ".",
|
||||
"resolveJsonModule": true
|
||||
}
|
||||
}
|
|
@ -441,6 +441,25 @@ importers:
|
|||
specifier: ^2.3.0
|
||||
version: 2.3.0(@types/node@18.13.0)(rollup@3.28.0)(vite@4.2.3)
|
||||
|
||||
packages/ui-plugin-bundler-kit:
|
||||
dependencies:
|
||||
vite:
|
||||
specifier: ^4.0.0 || ^5.0.0
|
||||
version: 4.2.3(@types/node@18.13.0)(sass@1.60.0)
|
||||
devDependencies:
|
||||
'@halo-dev/api-client':
|
||||
specifier: workspace:*
|
||||
version: link:../api-client
|
||||
'@types/js-yaml':
|
||||
specifier: ^4.0.9
|
||||
version: 4.0.9
|
||||
js-yaml:
|
||||
specifier: ^4.1.0
|
||||
version: 4.1.0
|
||||
unbuild:
|
||||
specifier: ^0.7.6
|
||||
version: 0.7.6
|
||||
|
||||
packages:
|
||||
|
||||
/@ampproject/remapping@2.2.0:
|
||||
|
@ -2037,7 +2056,6 @@ packages:
|
|||
cpu: [arm64]
|
||||
os: [android]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/android-arm@0.15.9:
|
||||
|
@ -2055,7 +2073,6 @@ packages:
|
|||
cpu: [arm]
|
||||
os: [android]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/android-x64@0.17.19:
|
||||
|
@ -2064,7 +2081,6 @@ packages:
|
|||
cpu: [x64]
|
||||
os: [android]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/darwin-arm64@0.17.19:
|
||||
|
@ -2073,7 +2089,6 @@ packages:
|
|||
cpu: [arm64]
|
||||
os: [darwin]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/darwin-x64@0.17.19:
|
||||
|
@ -2082,7 +2097,6 @@ packages:
|
|||
cpu: [x64]
|
||||
os: [darwin]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/freebsd-arm64@0.17.19:
|
||||
|
@ -2091,7 +2105,6 @@ packages:
|
|||
cpu: [arm64]
|
||||
os: [freebsd]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/freebsd-x64@0.17.19:
|
||||
|
@ -2100,7 +2113,6 @@ packages:
|
|||
cpu: [x64]
|
||||
os: [freebsd]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/linux-arm64@0.17.19:
|
||||
|
@ -2109,7 +2121,6 @@ packages:
|
|||
cpu: [arm64]
|
||||
os: [linux]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/linux-arm@0.17.19:
|
||||
|
@ -2118,7 +2129,6 @@ packages:
|
|||
cpu: [arm]
|
||||
os: [linux]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/linux-ia32@0.17.19:
|
||||
|
@ -2127,7 +2137,6 @@ packages:
|
|||
cpu: [ia32]
|
||||
os: [linux]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/linux-loong64@0.14.54:
|
||||
|
@ -2154,7 +2163,6 @@ packages:
|
|||
cpu: [loong64]
|
||||
os: [linux]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/linux-mips64el@0.17.19:
|
||||
|
@ -2163,7 +2171,6 @@ packages:
|
|||
cpu: [mips64el]
|
||||
os: [linux]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/linux-ppc64@0.17.19:
|
||||
|
@ -2172,7 +2179,6 @@ packages:
|
|||
cpu: [ppc64]
|
||||
os: [linux]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/linux-riscv64@0.17.19:
|
||||
|
@ -2181,7 +2187,6 @@ packages:
|
|||
cpu: [riscv64]
|
||||
os: [linux]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/linux-s390x@0.17.19:
|
||||
|
@ -2190,7 +2195,6 @@ packages:
|
|||
cpu: [s390x]
|
||||
os: [linux]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/linux-x64@0.17.19:
|
||||
|
@ -2199,7 +2203,6 @@ packages:
|
|||
cpu: [x64]
|
||||
os: [linux]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/netbsd-x64@0.17.19:
|
||||
|
@ -2208,7 +2211,6 @@ packages:
|
|||
cpu: [x64]
|
||||
os: [netbsd]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/openbsd-x64@0.17.19:
|
||||
|
@ -2217,7 +2219,6 @@ packages:
|
|||
cpu: [x64]
|
||||
os: [openbsd]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/sunos-x64@0.17.19:
|
||||
|
@ -2226,7 +2227,6 @@ packages:
|
|||
cpu: [x64]
|
||||
os: [sunos]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/win32-arm64@0.17.19:
|
||||
|
@ -2235,7 +2235,6 @@ packages:
|
|||
cpu: [arm64]
|
||||
os: [win32]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/win32-ia32@0.17.19:
|
||||
|
@ -2244,7 +2243,6 @@ packages:
|
|||
cpu: [ia32]
|
||||
os: [win32]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@esbuild/win32-x64@0.17.19:
|
||||
|
@ -2253,7 +2251,6 @@ packages:
|
|||
cpu: [x64]
|
||||
os: [win32]
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/@eslint-community/eslint-utils@4.4.0(eslint@8.43.0):
|
||||
|
@ -3927,6 +3924,10 @@ packages:
|
|||
resolution: {integrity: sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==}
|
||||
dev: true
|
||||
|
||||
/@types/js-yaml@4.0.9:
|
||||
resolution: {integrity: sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==}
|
||||
dev: true
|
||||
|
||||
/@types/jsdom@20.0.1:
|
||||
resolution: {integrity: sha512-d0r18sZPmMQr1eG35u12FZfhIXNrnsPU/g5wvRKCUf/tOGilKKwYMYGqh33BNR6ba+2gkHw1EUiHoN3mn7E5IQ==}
|
||||
dependencies:
|
||||
|
@ -4006,7 +4007,6 @@ packages:
|
|||
|
||||
/@types/node@18.13.0:
|
||||
resolution: {integrity: sha512-gC3TazRzGoOnoKAhUx+Q0t8S9Tzs74z7m0ipwGpSqQrleP14hKxP4/JUeEQcD3W1/aIpnWl8pHowI7WokuZpXg==}
|
||||
dev: true
|
||||
|
||||
/@types/node@8.10.66:
|
||||
resolution: {integrity: sha512-tktOkFUA4kXx2hhhrB8bIFb5TbwzS4uOhKEmwiD+NoiL0qtP2OQ9mFldbgD4dV1djrlBYP6eBuQZiWjuHUpqFw==}
|
||||
|
@ -6673,7 +6673,6 @@ packages:
|
|||
'@esbuild/win32-arm64': 0.17.19
|
||||
'@esbuild/win32-ia32': 0.17.19
|
||||
'@esbuild/win32-x64': 0.17.19
|
||||
dev: true
|
||||
|
||||
/escalade@3.1.1:
|
||||
resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==}
|
||||
|
@ -7788,7 +7787,6 @@ packages:
|
|||
|
||||
/immutable@4.1.0:
|
||||
resolution: {integrity: sha512-oNkuqVTA8jqG1Q6c+UglTOD1xhC1BtjKI7XkCXRkZHrN5m18/XsnUp8Q89GkQO/z+0WjonSvl0FLhDYftp46nQ==}
|
||||
dev: true
|
||||
|
||||
/import-fresh@3.3.0:
|
||||
resolution: {integrity: sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==}
|
||||
|
@ -10193,7 +10191,6 @@ packages:
|
|||
hasBin: true
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.2
|
||||
dev: true
|
||||
|
||||
/rope-sequence@1.3.3:
|
||||
resolution: {integrity: sha512-85aZYCxweiD5J8yTEbw+E6A27zSnLPNDL0WfPdw3YYodq7WjnTKo0q4dtyQ2gz23iPT8Q9CUyJtAaUNcTxRf5Q==}
|
||||
|
@ -10273,7 +10270,6 @@ packages:
|
|||
chokidar: 3.5.3
|
||||
immutable: 4.1.0
|
||||
source-map-js: 1.0.2
|
||||
dev: true
|
||||
|
||||
/saxes@6.0.0:
|
||||
resolution: {integrity: sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==}
|
||||
|
@ -11734,7 +11730,6 @@ packages:
|
|||
sass: 1.60.0
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.2
|
||||
dev: true
|
||||
|
||||
/vitest@0.18.1(@vitest/ui@0.34.1)(c8@7.12.0)(jsdom@20.0.3)(sass@1.60.0):
|
||||
resolution: {integrity: sha512-4F/1K/Vn4AvJwe7i2YblR02PT5vMKcw9KN4unDq2KD0YcSxX0B/6D6Qu9PJaXwVuxXMFTQ5ovd4+CQaW3bwofA==}
|
||||
|
|
Loading…
Reference in New Issue