@halo-dev/ui-plugin-bundler-kit 2.21.0 → 2.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +333 -0
- package/dist/index.d.ts +73 -8
- package/dist/index.js +218 -0
- package/package.json +17 -18
- package/src/constants/build.ts +4 -0
- package/src/constants/externals.ts +16 -0
- package/src/constants/halo-plugin.ts +3 -0
- package/src/index.ts +3 -0
- package/src/legacy.ts +69 -0
- package/src/rsbuild.ts +146 -0
- package/src/utils/halo-plugin.ts +11 -0
- package/src/vite.ts +85 -0
- package/tsconfig.json +18 -0
- package/tsdown.config.ts +10 -0
- package/dist/index.cjs +0 -3928
- package/dist/index.mjs +0 -3920
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const GLOBALS = {
|
|
2
|
+
vue: "Vue",
|
|
3
|
+
"vue-router": "VueRouter",
|
|
4
|
+
"@vueuse/core": "VueUse",
|
|
5
|
+
"@vueuse/components": "VueUse",
|
|
6
|
+
"@vueuse/router": "VueUse",
|
|
7
|
+
"@halo-dev/console-shared": "HaloConsoleShared",
|
|
8
|
+
"@halo-dev/components": "HaloComponents",
|
|
9
|
+
"@halo-dev/api-client": "HaloApiClient",
|
|
10
|
+
"@halo-dev/richtext-editor": "RichTextEditor",
|
|
11
|
+
axios: "axios",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const EXTERNALS = Object.keys(GLOBALS) as string[];
|
|
15
|
+
|
|
16
|
+
export { EXTERNALS, GLOBALS };
|
package/src/index.ts
ADDED
package/src/legacy.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
import { DEFAULT_OUT_DIR_DEV } from "./constants/build";
|
|
3
|
+
import { EXTERNALS, GLOBALS } from "./constants/externals";
|
|
4
|
+
import { DEFAULT_MANIFEST_PATH } from "./constants/halo-plugin";
|
|
5
|
+
import { getHaloPluginManifest } from "./utils/halo-plugin";
|
|
6
|
+
|
|
7
|
+
const LEGACY_OUT_DIR_PROD = "../src/main/resources/console";
|
|
8
|
+
|
|
9
|
+
interface HaloUIPluginBundlerKitOptions {
|
|
10
|
+
outDir?:
|
|
11
|
+
| string
|
|
12
|
+
| {
|
|
13
|
+
dev: string;
|
|
14
|
+
prod: string;
|
|
15
|
+
};
|
|
16
|
+
manifestPath?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Use `viteConfig` or `rsbuildConfig` instead.
|
|
21
|
+
*/
|
|
22
|
+
export function HaloUIPluginBundlerKit(
|
|
23
|
+
options: HaloUIPluginBundlerKitOptions = {}
|
|
24
|
+
): Plugin {
|
|
25
|
+
return {
|
|
26
|
+
name: "halo-ui-plugin-bundler-kit",
|
|
27
|
+
config(config, env) {
|
|
28
|
+
const isProduction = env.mode === "production";
|
|
29
|
+
|
|
30
|
+
let outDir = isProduction ? LEGACY_OUT_DIR_PROD : DEFAULT_OUT_DIR_DEV;
|
|
31
|
+
|
|
32
|
+
if (options.outDir) {
|
|
33
|
+
if (typeof options.outDir === "string") {
|
|
34
|
+
outDir = options.outDir;
|
|
35
|
+
} else {
|
|
36
|
+
outDir = isProduction ? options.outDir.prod : options.outDir.dev;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const manifestPath = options.manifestPath || DEFAULT_MANIFEST_PATH;
|
|
41
|
+
|
|
42
|
+
const manifest = getHaloPluginManifest(manifestPath);
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
...config,
|
|
46
|
+
define: {
|
|
47
|
+
"process.env": process.env,
|
|
48
|
+
},
|
|
49
|
+
build: {
|
|
50
|
+
outDir,
|
|
51
|
+
emptyOutDir: true,
|
|
52
|
+
lib: {
|
|
53
|
+
entry: "src/index.ts",
|
|
54
|
+
name: manifest.metadata.name,
|
|
55
|
+
formats: ["iife"],
|
|
56
|
+
fileName: () => "main.js",
|
|
57
|
+
},
|
|
58
|
+
rollupOptions: {
|
|
59
|
+
external: EXTERNALS,
|
|
60
|
+
output: {
|
|
61
|
+
globals: GLOBALS,
|
|
62
|
+
extend: true,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
package/src/rsbuild.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineConfig,
|
|
3
|
+
mergeRsbuildConfig,
|
|
4
|
+
type ConfigParams,
|
|
5
|
+
type RsbuildConfig,
|
|
6
|
+
type RsbuildMode,
|
|
7
|
+
} from "@rsbuild/core";
|
|
8
|
+
import { pluginVue } from "@rsbuild/plugin-vue";
|
|
9
|
+
import { DEFAULT_OUT_DIR_DEV, DEFAULT_OUT_DIR_PROD } from "./constants/build";
|
|
10
|
+
import { GLOBALS } from "./constants/externals";
|
|
11
|
+
import { DEFAULT_MANIFEST_PATH } from "./constants/halo-plugin";
|
|
12
|
+
import { getHaloPluginManifest } from "./utils/halo-plugin";
|
|
13
|
+
|
|
14
|
+
export interface RsBuildUserConfig {
|
|
15
|
+
/**
|
|
16
|
+
* Halo plugin manifest path.
|
|
17
|
+
*
|
|
18
|
+
* @default "../src/main/resources/plugin.yaml"
|
|
19
|
+
*/
|
|
20
|
+
manifestPath?: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Custom Rsbuild config.
|
|
24
|
+
*/
|
|
25
|
+
rsbuild: RsbuildConfig | ((env: ConfigParams) => RsbuildConfig);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function createRsbuildPresetsConfig(manifestPath: string) {
|
|
29
|
+
const manifest = getHaloPluginManifest(manifestPath);
|
|
30
|
+
|
|
31
|
+
return defineConfig(({ envMode }) => {
|
|
32
|
+
const isProduction = envMode === "production";
|
|
33
|
+
|
|
34
|
+
const outDir = isProduction ? DEFAULT_OUT_DIR_PROD : DEFAULT_OUT_DIR_DEV;
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
mode: (envMode as RsbuildMode) || "production",
|
|
38
|
+
plugins: [pluginVue()],
|
|
39
|
+
source: {
|
|
40
|
+
entry: {
|
|
41
|
+
main: "./src/index.ts",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
dev: {
|
|
45
|
+
hmr: false,
|
|
46
|
+
},
|
|
47
|
+
performance: {
|
|
48
|
+
chunkSplit: {
|
|
49
|
+
strategy: "custom",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
tools: {
|
|
53
|
+
rspack: {
|
|
54
|
+
optimization: {
|
|
55
|
+
splitChunks: {
|
|
56
|
+
chunks: "async",
|
|
57
|
+
},
|
|
58
|
+
moduleIds: "named",
|
|
59
|
+
},
|
|
60
|
+
experiments: {
|
|
61
|
+
rspackFuture: {
|
|
62
|
+
bundlerInfo: {
|
|
63
|
+
force: false,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
module: {
|
|
68
|
+
parser: {
|
|
69
|
+
javascript: {
|
|
70
|
+
importMeta: false,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
output: {
|
|
75
|
+
publicPath: `/plugins/${manifest.metadata.name}/assets/console/`,
|
|
76
|
+
library: {
|
|
77
|
+
type: "window",
|
|
78
|
+
export: "default",
|
|
79
|
+
name: manifest.metadata.name,
|
|
80
|
+
},
|
|
81
|
+
globalObject: "window",
|
|
82
|
+
iife: true,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
htmlPlugin: false,
|
|
86
|
+
},
|
|
87
|
+
output: {
|
|
88
|
+
distPath: {
|
|
89
|
+
root: outDir,
|
|
90
|
+
js: "",
|
|
91
|
+
css: "",
|
|
92
|
+
jsAsync: "chunks",
|
|
93
|
+
cssAsync: "chunks",
|
|
94
|
+
},
|
|
95
|
+
cleanDistPath: true,
|
|
96
|
+
filename: {
|
|
97
|
+
css: (pathData) => {
|
|
98
|
+
if (pathData.chunk?.name === "main") {
|
|
99
|
+
return "style.css";
|
|
100
|
+
}
|
|
101
|
+
return "[name].[contenthash:8].css";
|
|
102
|
+
},
|
|
103
|
+
js: (pathData) => {
|
|
104
|
+
if (pathData.chunk?.name === "main") {
|
|
105
|
+
return "main.js";
|
|
106
|
+
}
|
|
107
|
+
return "[name].[contenthash:8].js";
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
externals: GLOBALS,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Rsbuild config for Halo UI Plugin.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { rsbuildConfig } from "@halo-dev/ui-plugin-bundler-kit";
|
|
122
|
+
*
|
|
123
|
+
* export default rsbuildConfig({
|
|
124
|
+
* rsbuild: {
|
|
125
|
+
* // your custom rsbuild config
|
|
126
|
+
* },
|
|
127
|
+
* });
|
|
128
|
+
* ```
|
|
129
|
+
* @param config
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
132
|
+
export function rsbuildConfig(
|
|
133
|
+
config?: RsBuildUserConfig
|
|
134
|
+
): (env: ConfigParams) => RsbuildConfig {
|
|
135
|
+
const presetsConfigFn = createRsbuildPresetsConfig(
|
|
136
|
+
config?.manifestPath || DEFAULT_MANIFEST_PATH
|
|
137
|
+
);
|
|
138
|
+
return defineConfig((env) => {
|
|
139
|
+
const presetsConfig = presetsConfigFn(env);
|
|
140
|
+
const userConfig =
|
|
141
|
+
typeof config?.rsbuild === "function"
|
|
142
|
+
? config.rsbuild(env)
|
|
143
|
+
: config?.rsbuild || {};
|
|
144
|
+
return mergeRsbuildConfig(presetsConfig, userConfig);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Plugin as HaloPlugin } from "@halo-dev/api-client";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import yaml from "js-yaml";
|
|
4
|
+
|
|
5
|
+
export function getHaloPluginManifest(manifestPath: string) {
|
|
6
|
+
const manifest = yaml.load(
|
|
7
|
+
fs.readFileSync(manifestPath, "utf8")
|
|
8
|
+
) as HaloPlugin;
|
|
9
|
+
|
|
10
|
+
return manifest;
|
|
11
|
+
}
|
package/src/vite.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import Vue from "@vitejs/plugin-vue";
|
|
2
|
+
import {
|
|
3
|
+
defineConfig,
|
|
4
|
+
mergeConfig,
|
|
5
|
+
UserConfig,
|
|
6
|
+
UserConfigFnObject,
|
|
7
|
+
} from "vite";
|
|
8
|
+
import { DEFAULT_OUT_DIR_DEV, DEFAULT_OUT_DIR_PROD } from "./constants/build";
|
|
9
|
+
import { EXTERNALS, GLOBALS } from "./constants/externals";
|
|
10
|
+
import { DEFAULT_MANIFEST_PATH } from "./constants/halo-plugin";
|
|
11
|
+
import { getHaloPluginManifest } from "./utils/halo-plugin";
|
|
12
|
+
|
|
13
|
+
export interface ViteUserConfig {
|
|
14
|
+
/**
|
|
15
|
+
* Halo plugin manifest path.
|
|
16
|
+
*
|
|
17
|
+
* @default "../src/main/resources/plugin.yaml"
|
|
18
|
+
*/
|
|
19
|
+
manifestPath?: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Custom Vite config.
|
|
23
|
+
*/
|
|
24
|
+
vite: UserConfig | UserConfigFnObject;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function createVitePresetsConfig(manifestPath: string) {
|
|
28
|
+
const manifest = getHaloPluginManifest(manifestPath);
|
|
29
|
+
|
|
30
|
+
return defineConfig(({ mode }) => {
|
|
31
|
+
const isProduction = mode === "production";
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
mode: mode || "production",
|
|
35
|
+
plugins: [Vue()],
|
|
36
|
+
define: { "process.env.NODE_ENV": "'production'" },
|
|
37
|
+
build: {
|
|
38
|
+
outDir: isProduction ? DEFAULT_OUT_DIR_PROD : DEFAULT_OUT_DIR_DEV,
|
|
39
|
+
emptyOutDir: true,
|
|
40
|
+
lib: {
|
|
41
|
+
entry: "src/index.ts",
|
|
42
|
+
name: manifest.metadata.name,
|
|
43
|
+
formats: ["iife"],
|
|
44
|
+
fileName: () => "main.js",
|
|
45
|
+
cssFileName: "style",
|
|
46
|
+
},
|
|
47
|
+
rollupOptions: {
|
|
48
|
+
external: EXTERNALS,
|
|
49
|
+
output: {
|
|
50
|
+
globals: GLOBALS,
|
|
51
|
+
extend: true,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Vite config for Halo UI Plugin.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { viteConfig } from "@halo-dev/ui-plugin-bundler-kit";
|
|
65
|
+
*
|
|
66
|
+
* export default viteConfig({
|
|
67
|
+
* vite: {
|
|
68
|
+
* // your custom vite config
|
|
69
|
+
* },
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export function viteConfig(config?: ViteUserConfig) {
|
|
74
|
+
const presetsConfigFn = createVitePresetsConfig(
|
|
75
|
+
config?.manifestPath || DEFAULT_MANIFEST_PATH
|
|
76
|
+
);
|
|
77
|
+
return defineConfig((env) => {
|
|
78
|
+
const presetsConfig = presetsConfigFn(env);
|
|
79
|
+
const userConfig =
|
|
80
|
+
typeof config?.vite === "function"
|
|
81
|
+
? config.vite(env)
|
|
82
|
+
: config?.vite || {};
|
|
83
|
+
return mergeConfig(presetsConfig, userConfig);
|
|
84
|
+
});
|
|
85
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": ["src"],
|
|
3
|
+
"exclude": ["**/*.spec.ts"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"target": "ES2020",
|
|
7
|
+
"module": "ES2020",
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"noImplicitOverride": true,
|
|
13
|
+
"noUnusedLocals": true,
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"baseUrl": ".",
|
|
16
|
+
"resolveJsonModule": true
|
|
17
|
+
}
|
|
18
|
+
}
|