@yannick-z/modulo 0.2.0 → 0.3.1
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/.vscode/extensions.json +3 -0
- package/README.md +57 -60
- package/bin/modulo.js +29 -19
- package/biome.json +34 -0
- package/package.json +36 -35
- package/rslib.config.ts +19 -19
- package/src/args/get-framework-name.ts +7 -7
- package/src/args/index.ts +16 -74
- package/src/args/preset.ts +16 -16
- package/src/cli/init.ts +10 -6
- package/src/cli/pack-code.ts +20 -9
- package/src/config/example/example-config.ts +50 -39
- package/src/config/example/example-externals.ts +21 -37
- package/src/config/index.ts +186 -16
- package/src/config/presets.ts +100 -0
- package/src/config/type.ts +34 -12
- package/src/index.ts +104 -10
- package/src/initiator/create-config-file.ts +52 -36
- package/src/initiator/create-project.ts +249 -0
- package/src/initiator/modify-scripts.ts +42 -42
- package/src/packer/auto-external-plugin.ts +205 -0
- package/src/packer/collect-modules.ts +58 -69
- package/src/packer/get-externals-and-tags.ts +82 -55
- package/src/packer/lib.ts +78 -70
- package/src/packer/page.ts +105 -82
- package/src/packer/prepare.ts +63 -57
- package/src/tools/cli.ts +21 -0
- package/src/tools/file.ts +84 -14
- package/src/tools/find-path-root.ts +52 -25
- package/src/tools/get-framework-name.ts +7 -7
- package/src/tools/get-ui-plugin.ts +27 -13
- package/src/tools/json.ts +63 -9
- package/src/tools/log.ts +58 -0
- package/src/tools/merge-user-config.ts +17 -17
- package/src/tools/omit-root-path.ts +17 -7
- package/src/tools/panic.ts +12 -8
- package/src/tools/string.ts +13 -2
- package/src/type/guard.ts +22 -3
- package/tsconfig.json +9 -9
- package/dist/index.js +0 -773
- package/src/args/cmd.ts +0 -16
- package/src/args/mode.ts +0 -38
- package/src/args/node_env.ts +0 -15
- package/src/args/target.ts +0 -44
- package/src/config/externals.ts +0 -70
- package/src/config/generate_config.ts +0 -105
- package/src/config/preset/alias.ts +0 -3
- package/src/config/preset/dev-server.ts +0 -6
- package/src/config/preset/dirs.ts +0 -12
- package/src/config/preset/html.ts +0 -19
- package/src/config/preset/index.ts +0 -23
- package/src/config/preset/libs.ts +0 -5
- package/src/config/preset/minify.ts +0 -24
- package/src/config/preset/url.ts +0 -4
- package/src/tools/debug-log.ts +0 -37
package/src/cli/pack-code.ts
CHANGED
|
@@ -3,15 +3,26 @@ import { lib_pack } from "../packer/lib.ts";
|
|
|
3
3
|
import { page_pack } from "../packer/page.ts";
|
|
4
4
|
|
|
5
5
|
export async function pack_code(args: ModuloArgs_Pack) {
|
|
6
|
-
|
|
6
|
+
const { target } = args;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
8
|
+
if (args.cmd === "preview") {
|
|
9
|
+
await page_pack(args);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
//先构建页面,防止产物目录被清理掉
|
|
14
|
+
// target为all的时候不允许watch,只能分别启动两个进程
|
|
15
|
+
// 针对 dev 模式优化:并行启动 page 和 module
|
|
16
|
+
if (target === "all" && args.cmd === "dev") {
|
|
17
|
+
await Promise.all([page_pack(args), lib_pack(args)]);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (target === "page" || target === "all") {
|
|
22
|
+
await page_pack(args);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (target === "module" || target === "all") {
|
|
26
|
+
await lib_pack(args);
|
|
27
|
+
}
|
|
17
28
|
}
|
|
@@ -1,46 +1,57 @@
|
|
|
1
1
|
import picocolors from "picocolors";
|
|
2
2
|
import { star_line } from "../../initiator/modify-scripts.ts";
|
|
3
|
-
import { preset_alias } from "../
|
|
4
|
-
import { preset_config } from "../preset/index.ts";
|
|
3
|
+
import { preset_alias, preset_config, preset_ui_libs } from "../presets.ts";
|
|
5
4
|
import type { USER_CONFIG } from "../type.ts";
|
|
6
5
|
import { common_example_externals, presets } from "./example-externals.ts";
|
|
7
6
|
|
|
8
|
-
export function get_example_config(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
7
|
+
export function get_example_config(
|
|
8
|
+
preset?: keyof typeof preset_ui_libs | undefined,
|
|
9
|
+
) {
|
|
10
|
+
console.log(
|
|
11
|
+
picocolors.magenta(
|
|
12
|
+
`\n${star_line}\n默认配置文件中的externals内容为推荐内容\n请注意手动替换配置文件中externals的url,以保证符合项目需求\n如果不需要externals部分依赖,也可以将他们从列表中删除\n${star_line}\n`,
|
|
13
|
+
),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
let externals = common_example_externals;
|
|
17
|
+
if (preset) {
|
|
18
|
+
if (preset === "react19") {
|
|
19
|
+
externals = presets.react19;
|
|
20
|
+
} else if (preset === "vue2" || preset === "vue2") {
|
|
21
|
+
externals = presets.vue2;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
// 提供一些常用的配置
|
|
27
|
+
input: preset_config.input,
|
|
28
|
+
output: {
|
|
29
|
+
filenameHash: true,
|
|
30
|
+
},
|
|
31
|
+
url: {
|
|
32
|
+
base: "/",
|
|
33
|
+
},
|
|
34
|
+
alias: preset_alias,
|
|
35
|
+
html: {
|
|
36
|
+
root: "app",
|
|
37
|
+
title: "Modulo Page",
|
|
38
|
+
meta: {},
|
|
39
|
+
tags: [
|
|
40
|
+
{
|
|
41
|
+
tag: "script",
|
|
42
|
+
attrs: {
|
|
43
|
+
src: "/packages/webhost/dist/webhost.system.js",
|
|
44
|
+
},
|
|
45
|
+
append: false,
|
|
46
|
+
publicPath: false,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
dev_server: {
|
|
51
|
+
proxy: preset_config.dev_server.proxy,
|
|
52
|
+
},
|
|
53
|
+
externals,
|
|
54
|
+
} as USER_CONFIG;
|
|
44
55
|
}
|
|
45
56
|
|
|
46
|
-
export const default_config_file_name = "modulo.config.
|
|
57
|
+
export const default_config_file_name = "modulo.config.ts";
|
|
@@ -1,47 +1,31 @@
|
|
|
1
|
-
import type { ExternalLibs } from "../
|
|
1
|
+
import type { ExternalLibs } from "../type.ts";
|
|
2
2
|
|
|
3
3
|
// 构建会将以下依赖排除在外,不打包进产物,也可配置更多的依赖
|
|
4
4
|
export const vue2_example_externals: ExternalLibs = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
esm: "https://cdn.jsdelivr.net/npm/vue@2.7.16/+esm",
|
|
15
|
-
},
|
|
16
|
-
},
|
|
5
|
+
vue: {
|
|
6
|
+
// 支持多个importName,以避免import Vue from 'Vue'这种不正规的写法
|
|
7
|
+
importName: ["vue", "Vue"],
|
|
8
|
+
// preset代表初始化配置的时候能够减少无用配置,比如vue的preset会自动过滤只配置vue的externals
|
|
9
|
+
// url可以直接写字符串,则无论哪种打包模式,都使用这个url
|
|
10
|
+
// 也可以分别提供umd和esm的url,则会根据打包模式自动切换
|
|
11
|
+
// 另外还支持dev和prd模式分别提供不同的url
|
|
12
|
+
url: "https://cdn.jsdelivr.net/npm/vue@2.7.16/+esm",
|
|
13
|
+
},
|
|
17
14
|
};
|
|
18
|
-
export const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
// 不写importName,则默认使用libName作为importName
|
|
27
|
-
"react-dom": {
|
|
28
|
-
umd: "/packages/common/js/react-17.0.2/umd/react-dom.production.min.js",
|
|
29
|
-
esm: "https://cdn.jsdelivr.net/npm/react-dom@17.0.2/+esm",
|
|
30
|
-
},
|
|
31
|
-
"react/jsx-runtime": {
|
|
32
|
-
umd: "/packages/common/js/react-17.0.2/umd/react-jsx-runtime.js",
|
|
33
|
-
esm: "/packages/common/js/react-17.0.2/esm/react-jsx-runtime.js",
|
|
34
|
-
},
|
|
15
|
+
export const react19_example_externals: ExternalLibs = {
|
|
16
|
+
react: {
|
|
17
|
+
importName: ["react", "React"],
|
|
18
|
+
url: "https://esm.sh/react@19.2.4",
|
|
19
|
+
},
|
|
20
|
+
"react-dom": "https://esm.sh/react-dom@19.2.4",
|
|
21
|
+
"react/jsx-runtime": "https://esm.sh/react@19.2.4/jsx-runtime",
|
|
35
22
|
};
|
|
36
23
|
export const common_example_externals: ExternalLibs = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
umd: "https://cdn.jsdelivr.net/npm/rxjs@7.8.2/dist/bundles/rxjs.umd.min.js",
|
|
40
|
-
esm: "https://cdn.jsdelivr.net/npm/rxjs@7.8.2/+esm",
|
|
41
|
-
},
|
|
24
|
+
jquery: "https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js",
|
|
25
|
+
rxjs: "https://cdn.jsdelivr.net/npm/rxjs@7.8.2/+esm",
|
|
42
26
|
};
|
|
43
27
|
|
|
44
28
|
export const presets = {
|
|
45
|
-
|
|
46
|
-
|
|
29
|
+
vue2: { ...vue2_example_externals, ...common_example_externals },
|
|
30
|
+
react19: { ...react19_example_externals, ...common_example_externals },
|
|
47
31
|
};
|
package/src/config/index.ts
CHANGED
|
@@ -1,27 +1,197 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { cwd } from "node:process";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import type { ModuloArgs_Pack } from "../args/index.ts";
|
|
6
|
+
import { debug_log } from "../tools/log.ts";
|
|
1
7
|
import { resolve_and_read } from "../tools/file.ts";
|
|
2
8
|
import { jsonparse } from "../tools/json.ts";
|
|
9
|
+
import { merge_user_config } from "../tools/merge-user-config.ts";
|
|
3
10
|
import { PANIC_IF } from "../tools/panic.ts";
|
|
4
|
-
import {
|
|
11
|
+
import { preset_config, preset_minify_config } from "./presets.ts";
|
|
12
|
+
import type { GLOBAL_CONFIG, USER_CONFIG } from "./type.ts";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 命令启动时候的目录作为根目录
|
|
16
|
+
*/
|
|
17
|
+
export const root = cwd();
|
|
5
18
|
|
|
6
19
|
interface PackageJson {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
20
|
+
name: string;
|
|
21
|
+
dependencies: Record<string, string>;
|
|
22
|
+
scripts: undefined | Record<string, string>;
|
|
10
23
|
}
|
|
11
24
|
/**
|
|
12
|
-
*
|
|
25
|
+
* 读取并缓存 package.json 内容
|
|
26
|
+
* @returns package.json 的对象
|
|
27
|
+
* @throws 当文件不存在或缺少 name 字段时抛出异常
|
|
13
28
|
*/
|
|
14
29
|
let packagejson = null as PackageJson | null;
|
|
15
|
-
export function get_packagejson() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
export function get_packagejson(customRoot: string = root) {
|
|
31
|
+
if (!packagejson) {
|
|
32
|
+
// biome-ignore lint/style/noNonNullAssertion: <panic if content nullable>
|
|
33
|
+
packagejson = jsonparse<PackageJson>(
|
|
34
|
+
resolve_and_read(customRoot, "package.json"),
|
|
35
|
+
)!;
|
|
36
|
+
PANIC_IF(!packagejson, "根目录下没有package.json");
|
|
37
|
+
PANIC_IF(!packagejson.name, "package.json缺少name字段");
|
|
38
|
+
} else if (customRoot !== root) {
|
|
39
|
+
// 如果传入了自定义 root,强制重新读取,不使用缓存
|
|
40
|
+
const newPackageJson = jsonparse<PackageJson>(
|
|
41
|
+
resolve_and_read(customRoot, "package.json"),
|
|
42
|
+
)!;
|
|
43
|
+
PANIC_IF(!newPackageJson, "根目录下没有package.json");
|
|
44
|
+
PANIC_IF(!newPackageJson.name, "package.json缺少name字段");
|
|
45
|
+
return newPackageJson;
|
|
46
|
+
}
|
|
47
|
+
return packagejson;
|
|
25
48
|
}
|
|
26
49
|
|
|
27
|
-
|
|
50
|
+
let global_config: GLOBAL_CONFIG;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 获取全局配置(单例模式)
|
|
54
|
+
*
|
|
55
|
+
* 1. 读取用户配置文件
|
|
56
|
+
* 2. 处理 extends 继承逻辑
|
|
57
|
+
* 3. 与默认配置进行合并
|
|
58
|
+
* 4. 处理路径别名、环境变量、目录解析等
|
|
59
|
+
*
|
|
60
|
+
* @param args CLI 参数
|
|
61
|
+
* @returns 合并后的全局配置对象
|
|
62
|
+
*/
|
|
63
|
+
export async function get_global_config(
|
|
64
|
+
args: ModuloArgs_Pack,
|
|
65
|
+
): Promise<GLOBAL_CONFIG> {
|
|
66
|
+
if (!global_config) {
|
|
67
|
+
/**
|
|
68
|
+
* 读取配置文件
|
|
69
|
+
*/
|
|
70
|
+
let configPath = args.pack.config;
|
|
71
|
+
|
|
72
|
+
// Find config file if not specified
|
|
73
|
+
if (!configPath) {
|
|
74
|
+
const candidates = [
|
|
75
|
+
"modulo.config.ts",
|
|
76
|
+
"modulo.config.js",
|
|
77
|
+
"modulo.config.json",
|
|
78
|
+
];
|
|
79
|
+
for (const f of candidates) {
|
|
80
|
+
const p = resolve(root, f);
|
|
81
|
+
if (existsSync(p)) {
|
|
82
|
+
configPath = p;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!configPath) {
|
|
89
|
+
throw new Error("根目录下没有配置文件 (modulo.config.ts/js/json)");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const resolvedConfigPath = resolve(root, configPath);
|
|
93
|
+
|
|
94
|
+
// Load config using native import()
|
|
95
|
+
// Support .ts files via Node.js native support (requires Node.js v24+ or experimental flags)
|
|
96
|
+
let user_config: USER_CONFIG;
|
|
97
|
+
try {
|
|
98
|
+
const fileUrl = pathToFileURL(resolvedConfigPath).href;
|
|
99
|
+
const mod = await import(fileUrl);
|
|
100
|
+
user_config = mod.default || mod;
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.error(`无法加载配置文件: ${resolvedConfigPath}`);
|
|
103
|
+
throw e;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
PANIC_IF(!user_config, "根目录下没有配置文件");
|
|
107
|
+
debug_log("input user config", user_config);
|
|
108
|
+
|
|
109
|
+
if (user_config.extends) {
|
|
110
|
+
const extend_config_path = resolve(root, user_config.extends);
|
|
111
|
+
try {
|
|
112
|
+
const extend_fileUrl = pathToFileURL(extend_config_path).href;
|
|
113
|
+
const extend_mod = await import(extend_fileUrl);
|
|
114
|
+
const extend_config = extend_mod.default || extend_mod;
|
|
115
|
+
debug_log("extend config", extend_config);
|
|
116
|
+
merge_user_config(preset_config, extend_config);
|
|
117
|
+
} catch (e) {
|
|
118
|
+
console.error(`无法加载继承的配置文件: ${extend_config_path}`);
|
|
119
|
+
throw e;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 将配置文件和默认配置合并
|
|
125
|
+
*/
|
|
126
|
+
merge_user_config(preset_config, user_config);
|
|
127
|
+
const _config: GLOBAL_CONFIG = preset_config;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* src目录
|
|
131
|
+
*/
|
|
132
|
+
const src = resolve(root, _config.input.src);
|
|
133
|
+
const input = {
|
|
134
|
+
modules: resolve(src, _config.input.modules),
|
|
135
|
+
pages: resolve(src, _config.input.pages),
|
|
136
|
+
src: src,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* dist目录
|
|
141
|
+
*/
|
|
142
|
+
const dist = resolve(root, _config.output.dist);
|
|
143
|
+
const output = {
|
|
144
|
+
..._config.output,
|
|
145
|
+
dist: dist,
|
|
146
|
+
modules: resolve(dist, _config.output.modules),
|
|
147
|
+
pages: resolve(dist, _config.output.pages),
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 允许定制template
|
|
152
|
+
*/
|
|
153
|
+
const html = _config.html?.template
|
|
154
|
+
? { ..._config.html, template: resolve(root, _config.html.template) }
|
|
155
|
+
: _config.html;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 所有define的值都序列化以正确传入
|
|
159
|
+
*/
|
|
160
|
+
// process.env.NODE_ENV 由构建工具自动注入,不需要手动注入,否则会产生冲突警告
|
|
161
|
+
const define = Object.fromEntries(
|
|
162
|
+
Object.entries({
|
|
163
|
+
..._config.define,
|
|
164
|
+
"import.meta.env.MOUNT_ID": _config.html.root,
|
|
165
|
+
}).map(([k, v]) => [k, JSON.stringify(v)]),
|
|
166
|
+
);
|
|
167
|
+
debug_log("当前模式", process.env.NODE_ENV);
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* minify代码的开关
|
|
171
|
+
*/
|
|
172
|
+
const minify =
|
|
173
|
+
_config.minify === true ? preset_minify_config : _config.minify;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* alias 允许使用{src}作为占位符,取值来自input.src
|
|
177
|
+
*/
|
|
178
|
+
const alias = Object.fromEntries(
|
|
179
|
+
Object.entries(_config.alias).map(([k, v]) => [
|
|
180
|
+
k,
|
|
181
|
+
v.replace("{input.src}", input.src),
|
|
182
|
+
]),
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
global_config = {
|
|
186
|
+
..._config,
|
|
187
|
+
define,
|
|
188
|
+
html,
|
|
189
|
+
input,
|
|
190
|
+
minify,
|
|
191
|
+
output,
|
|
192
|
+
alias,
|
|
193
|
+
};
|
|
194
|
+
debug_log("global config", global_config);
|
|
195
|
+
}
|
|
196
|
+
return global_config;
|
|
197
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { OutputConfig } from "@rsbuild/core";
|
|
2
|
+
import type { ExternalLibs } from "./type.ts";
|
|
3
|
+
|
|
4
|
+
export const preset_alias: Record<string, string> = {
|
|
5
|
+
"@": "{input.src}",
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const preset_dev_server_config = {
|
|
9
|
+
open: false as false | string[], // dev时是否自动打开指定页面
|
|
10
|
+
port: 8080, // 开发页面时, dev-server服务器端口
|
|
11
|
+
proxy: {} as Record<
|
|
12
|
+
string,
|
|
13
|
+
string | { target: string; pathRewrite?: Record<string, string>; changeOrigin?: boolean; secure?: boolean }
|
|
14
|
+
>, // dev时的代理配置
|
|
15
|
+
};
|
|
16
|
+
export type DEV_SERVER_CONFIG = typeof preset_dev_server_config;
|
|
17
|
+
|
|
18
|
+
export const preset_input_dirs = {
|
|
19
|
+
src: "src", // 源码目录
|
|
20
|
+
pages: "pages", // 页面目录
|
|
21
|
+
modules: "modules", // 组件目录
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const preset_output_dirs = {
|
|
25
|
+
dist: "dist", // 源码目录
|
|
26
|
+
pages: "", // 页面目录输出目录,默认使用dist/..
|
|
27
|
+
modules: "modules", // 组件输出目录,默认使用dist/modules/..
|
|
28
|
+
filenameHash: true,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export interface Tag {
|
|
32
|
+
append?: boolean;
|
|
33
|
+
attrs?: Record<string, string>;
|
|
34
|
+
children?: string;
|
|
35
|
+
hash?: boolean | string;
|
|
36
|
+
head?: boolean;
|
|
37
|
+
publicPath?: string | boolean;
|
|
38
|
+
tag: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const default_html_config = {
|
|
42
|
+
meta: {} as Record<string, string>,
|
|
43
|
+
root: "", // html挂载点id, 只允许id
|
|
44
|
+
tags: [] as Tag[],
|
|
45
|
+
template: "", // html模板的路径
|
|
46
|
+
title: "", // html标题
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type HTML_CONFIG = typeof default_html_config;
|
|
50
|
+
|
|
51
|
+
export const preset_ui_libs = {
|
|
52
|
+
// 对ui库做严格的版本限制,以提高统一程度
|
|
53
|
+
react19: "19.2.4",
|
|
54
|
+
vue2: "2.7.16",
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const preset_minify_config: OutputConfig["minify"] = {
|
|
58
|
+
js: true,
|
|
59
|
+
jsOptions: {
|
|
60
|
+
minimizerOptions: {
|
|
61
|
+
compress: {
|
|
62
|
+
dead_code: true,
|
|
63
|
+
defaults: false,
|
|
64
|
+
toplevel: true,
|
|
65
|
+
unused: true,
|
|
66
|
+
},
|
|
67
|
+
format: {
|
|
68
|
+
comments: "some",
|
|
69
|
+
ecma: 2015,
|
|
70
|
+
preserve_annotations: true,
|
|
71
|
+
safari10: true,
|
|
72
|
+
semicolons: false,
|
|
73
|
+
},
|
|
74
|
+
mangle: true,
|
|
75
|
+
minify: true,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const preset_url_config = {
|
|
81
|
+
base: "/", // 前缀路径
|
|
82
|
+
cdn: "", // 可以将除了html资源以外的资源都部署到cdn上,比如https://cdn.host.com/,或者https://cdn.host.com/cdn-path/
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const preset_config = {
|
|
86
|
+
analyze: false, // 是否执行bundleAnalyze
|
|
87
|
+
define: {} as Record<string, string | boolean | number>, // 配置全局变量,用于打包时替换代码中的全局变量
|
|
88
|
+
dev_server: preset_dev_server_config,
|
|
89
|
+
externals: {} as ExternalLibs,
|
|
90
|
+
html: default_html_config,
|
|
91
|
+
input: preset_input_dirs,
|
|
92
|
+
minify: preset_minify_config as OutputConfig["minify"], // 是否压缩产物,同时进行mangle
|
|
93
|
+
output: preset_output_dirs,
|
|
94
|
+
ui_lib: preset_ui_libs,
|
|
95
|
+
url: preset_url_config,
|
|
96
|
+
alias: preset_alias,
|
|
97
|
+
webhost: true as boolean | "auto",
|
|
98
|
+
autoExternal: true, // 是否自动external
|
|
99
|
+
externalsType: "importmap" as "importmap" | "script", // external的类型
|
|
100
|
+
};
|
package/src/config/type.ts
CHANGED
|
@@ -1,17 +1,39 @@
|
|
|
1
|
-
import type { preset_config } from "./
|
|
1
|
+
import type { preset_config } from "./presets.ts";
|
|
2
2
|
|
|
3
3
|
export type GLOBAL_CONFIG = typeof preset_config;
|
|
4
4
|
|
|
5
|
+
export interface EnvExternalUrl {
|
|
6
|
+
dev: string;
|
|
7
|
+
prd: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type ConfigExternalUrl = EnvExternalUrl | string;
|
|
11
|
+
|
|
12
|
+
export interface ImportExternal {
|
|
13
|
+
url: ConfigExternalUrl;
|
|
14
|
+
importName?: string | string[];
|
|
15
|
+
global?: string; // script注入时使用的全局变量名
|
|
16
|
+
preset?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type ExternalLibs = {
|
|
20
|
+
[name: string]: ImportExternal | EnvExternalUrl | string;
|
|
21
|
+
};
|
|
22
|
+
|
|
5
23
|
export interface USER_CONFIG {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
24
|
+
extends?: string;
|
|
25
|
+
analyze?: boolean;
|
|
26
|
+
define?: GLOBAL_CONFIG["define"];
|
|
27
|
+
dev_server?: Partial<GLOBAL_CONFIG["dev_server"]>;
|
|
28
|
+
externals?: GLOBAL_CONFIG["externals"];
|
|
29
|
+
html?: Partial<GLOBAL_CONFIG["html"]>;
|
|
30
|
+
input?: Partial<GLOBAL_CONFIG["input"]>;
|
|
31
|
+
minify?: Partial<GLOBAL_CONFIG["minify"]> | boolean;
|
|
32
|
+
output?: Partial<GLOBAL_CONFIG["output"]>;
|
|
33
|
+
ui_lib?: Partial<GLOBAL_CONFIG["ui_lib"]>;
|
|
34
|
+
alias?: GLOBAL_CONFIG["alias"];
|
|
35
|
+
url?: Partial<GLOBAL_CONFIG["url"]>;
|
|
36
|
+
webhost?: GLOBAL_CONFIG["webhost"];
|
|
37
|
+
autoExternal?: boolean;
|
|
38
|
+
externalsType?: "importmap" | "script";
|
|
17
39
|
}
|