@gct-paas/build 0.1.12 → 0.1.14

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/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.14] - 2026-05-13
11
+
12
+ ### Added
13
+
14
+ - 补充排除 native 为外部依赖
15
+
16
+ ## [0.1.13] - 2026-05-13
17
+
18
+ ### Added
19
+
20
+ - vite defineProjectViteConfig 配置支持 plugin 分开配置
21
+
10
22
  ## [0.1.12] - 2026-05-08
11
23
 
12
24
  ### Changed
@@ -16,6 +16,6 @@ const DEFAULT_EXTERNAL = exports.DEFAULT_EXTERNAL = ["@babel/standalone", "espri
16
16
  // 图标库相关依赖
17
17
  "@ant-design/icons-vue", "@icon-park/vue-next/es/all", "@icon-park/vue-next/icons.json",
18
18
  // @gct-paas 底包相关依赖
19
- "@gct-paas/api", "@gct-paas/core", "@gct-paas/core-components", "@gct-paas/core-mobile", "@gct-paas/core-web", "@gct-paas/core-pad", "@gct-paas/design", "@gct-paas/design-mobile", "@gct-paas/design-web", "@gct-paas/design-pad", "@gct-paas/render", "@gct-paas/render-mobile", "@gct-paas/render-pad", "@gct-paas/render-web", "@gct-paas/schema", "@gct-paas/scss",
19
+ "@gct-paas/api", "@gct-paas/core", "@gct-paas/core-components", "@gct-paas/core-mobile", "@gct-paas/core-web", "@gct-paas/core-pad", "@gct-paas/design", "@gct-paas/design-mobile", "@gct-paas/design-web", "@gct-paas/design-pad", "@gct-paas/native", "@gct-paas/render", "@gct-paas/render-mobile", "@gct-paas/render-pad", "@gct-paas/render-web", "@gct-paas/schema", "@gct-paas/scss",
20
20
  // @gct-paas 独立组件库
21
21
  "@gct-paas/platform-icons", "@gct-paas/vue-pdf", "@gct-paas/vue-video-player", "@gct-paas/flow", "@gct-paas/monaco-vue-editor"];
@@ -27,7 +27,7 @@ function defineProjectViteConfig(opts = {}) {
27
27
  base: "./",
28
28
  build: {
29
29
  rolldownOptions: {
30
- external: _constants.DEFAULT_EXTERNAL
30
+ external: opts.ignoreDefaultExternal ? [] : _constants.DEFAULT_EXTERNAL
31
31
  }
32
32
  },
33
33
  css: {
@@ -56,7 +56,7 @@ function defineProjectViteConfig(opts = {}) {
56
56
  },
57
57
  plugins: [(0, _pluginVue.default)(), (0, _pluginVueJsx.default)(), (0, _vite2.default)({
58
58
  hmrTopLevelAwait: false
59
- }), (0, _injectImportmapPlugin.injectImportMapPlugin)()]
59
+ }), (0, _injectImportmapPlugin.injectImportMapPlugin)(opts.pluginCfg?.injectImportMap)]
60
60
  }, opts);
61
61
  });
62
62
  }
@@ -1,12 +1,34 @@
1
1
  import { UserConfig, UserConfigFnPromise } from 'vite';
2
+ import { InjectImportMapPluginOptions } from '../vite-plugins/inject-importmap-plugin';
3
+ export interface CustomUserConfig extends UserConfig {
4
+ /**
5
+ * 自定义插件配置
6
+ *
7
+ * @type {{
8
+ * injectImportMap?: Partial<InjectImportMapPluginOptions>;
9
+ * }}
10
+ */
11
+ pluginCfg?: {
12
+ /**
13
+ * 注入 import-map 配置的插件选项
14
+ *
15
+ * @type {Partial<InjectImportMapPluginOptions>}
16
+ */
17
+ injectImportMap?: Partial<InjectImportMapPluginOptions>;
18
+ };
19
+ /**
20
+ * 忽略默认外部依赖配置,默认为 false,即会将 DEFAULT_EXTERNAL 中的依赖配置为 external,设置为 true 则不会将 DEFAULT_EXTERNAL 中的依赖配置为 external
21
+ *
22
+ * @type {boolean}
23
+ */
24
+ ignoreDefaultExternal?: boolean;
25
+ }
2
26
  /**
3
27
  * 构建本地开发 project 项目 vite 通用配置,基于此配置构建其他 vite 配置
4
28
  * 参数合并时,数组会被合并而不是被替换
5
29
  *
6
- * @author chitanda
7
- * @date 2025-08-24 11:08:04
8
30
  * @export
9
31
  * @param {UserConfig} [opts={}]
10
- * @returns {*} {Promise<UserConfig>}
32
+ * @return {*} {UserConfigFnPromise}
11
33
  */
12
- export declare function defineProjectViteConfig(opts?: UserConfig): UserConfigFnPromise;
34
+ export declare function defineProjectViteConfig(opts?: CustomUserConfig): UserConfigFnPromise;
@@ -13,7 +13,8 @@ const DEV_IMPORT_MAP_PREFIX = ["/plugin-design/@id/", "/plugin-render-mobile/@id
13
13
  function injectImportMapPlugin(options = {}) {
14
14
  const {
15
15
  repoUrl = "https://git.gct-china.com/paas/frontend/gct-paas-cdn.git",
16
- filePath = "extras/import-map.json"
16
+ filePath = "extras/import-map.json",
17
+ packageDependencies = false
17
18
  } = options;
18
19
  let importMapContent = "{}";
19
20
  return {
@@ -63,6 +64,21 @@ function injectImportMapPlugin(options = {}) {
63
64
  const rawContent = _nodeFs.default.readFileSync(targetFilePath, "utf-8");
64
65
  try {
65
66
  const parsed = JSON.parse(rawContent);
67
+ if (parsed.imports && packageDependencies) {
68
+ const usedPackages = /* @__PURE__ */new Set();
69
+ const pkgPath = _nodePath.default.resolve(cwd, "package.json");
70
+ if (_nodeFs.default.existsSync(pkgPath)) {
71
+ const pkg = JSON.parse(_nodeFs.default.readFileSync(pkgPath, "utf-8"));
72
+ const dependenciesKeys = Object.keys(pkg.dependencies || {});
73
+ dependenciesKeys.forEach(dep => usedPackages.add(dep));
74
+ Object.keys(parsed.imports).forEach(key => {
75
+ const pkgName = key.split("/")[0];
76
+ if (!usedPackages.has(pkgName)) {
77
+ delete parsed.imports[key];
78
+ }
79
+ });
80
+ }
81
+ }
66
82
  if ((0, _util.isBuildPluginEnv)() && parsed.imports) {
67
83
  const keys = Object.keys(parsed.imports);
68
84
  DEV_IMPORT_MAP_PREFIX.forEach(prefix => {
@@ -1,17 +1,35 @@
1
1
  import type { Plugin } from 'vite';
2
+ /**
3
+ * 从远程 Git 仓库拉取 import-map.json 文件,并在构建时注入到 HTML 中的 Vite 插件
4
+ *
5
+ * @export
6
+ * @interface InjectImportMapPluginOptions
7
+ */
2
8
  export interface InjectImportMapPluginOptions {
3
9
  /**
4
10
  * 仓库地址,默认为 https://git.gct-china.com/paas/frontend/gct-paas-cdn.git
11
+ *
12
+ * @type {boolean}
5
13
  */
6
14
  repoUrl?: string;
7
15
  /**
8
16
  * 需要读取的文件路径,默认为 extras/import-map.json
17
+ *
18
+ * @type {boolean}
9
19
  */
10
20
  filePath?: string;
11
21
  /**
12
22
  * 指定分支,若未指定则自动获取当前主工程对应的分支
23
+ *
24
+ * @type {boolean}
13
25
  */
14
26
  branch?: string;
27
+ /**
28
+ * 是否过滤一下只生成使用到的包
29
+ *
30
+ * @type {boolean}
31
+ */
32
+ packageDependencies?: boolean;
15
33
  }
16
34
  /**
17
35
  * 编译时读取并注入 import-map 配置的插件
@@ -49,6 +49,7 @@ export const DEFAULT_EXTERNAL = [
49
49
  "@gct-paas/design-mobile",
50
50
  "@gct-paas/design-web",
51
51
  "@gct-paas/design-pad",
52
+ "@gct-paas/native",
52
53
  "@gct-paas/render",
53
54
  "@gct-paas/render-mobile",
54
55
  "@gct-paas/render-pad",
@@ -1,12 +1,34 @@
1
1
  import { UserConfig, UserConfigFnPromise } from 'vite';
2
+ import { InjectImportMapPluginOptions } from '../vite-plugins/inject-importmap-plugin';
3
+ export interface CustomUserConfig extends UserConfig {
4
+ /**
5
+ * 自定义插件配置
6
+ *
7
+ * @type {{
8
+ * injectImportMap?: Partial<InjectImportMapPluginOptions>;
9
+ * }}
10
+ */
11
+ pluginCfg?: {
12
+ /**
13
+ * 注入 import-map 配置的插件选项
14
+ *
15
+ * @type {Partial<InjectImportMapPluginOptions>}
16
+ */
17
+ injectImportMap?: Partial<InjectImportMapPluginOptions>;
18
+ };
19
+ /**
20
+ * 忽略默认外部依赖配置,默认为 false,即会将 DEFAULT_EXTERNAL 中的依赖配置为 external,设置为 true 则不会将 DEFAULT_EXTERNAL 中的依赖配置为 external
21
+ *
22
+ * @type {boolean}
23
+ */
24
+ ignoreDefaultExternal?: boolean;
25
+ }
2
26
  /**
3
27
  * 构建本地开发 project 项目 vite 通用配置,基于此配置构建其他 vite 配置
4
28
  * 参数合并时,数组会被合并而不是被替换
5
29
  *
6
- * @author chitanda
7
- * @date 2025-08-24 11:08:04
8
30
  * @export
9
31
  * @param {UserConfig} [opts={}]
10
- * @returns {*} {Promise<UserConfig>}
32
+ * @return {*} {UserConfigFnPromise}
11
33
  */
12
- export declare function defineProjectViteConfig(opts?: UserConfig): UserConfigFnPromise;
34
+ export declare function defineProjectViteConfig(opts?: CustomUserConfig): UserConfigFnPromise;
@@ -23,7 +23,7 @@ export function defineProjectViteConfig(opts = {}) {
23
23
  base: "./",
24
24
  build: {
25
25
  rolldownOptions: {
26
- external: DEFAULT_EXTERNAL
26
+ external: opts.ignoreDefaultExternal ? [] : DEFAULT_EXTERNAL
27
27
  }
28
28
  },
29
29
  css: {
@@ -54,7 +54,7 @@ export function defineProjectViteConfig(opts = {}) {
54
54
  vue(),
55
55
  vueJsx(),
56
56
  UnoCSS({ hmrTopLevelAwait: false }),
57
- injectImportMapPlugin()
57
+ injectImportMapPlugin(opts.pluginCfg?.injectImportMap)
58
58
  ]
59
59
  },
60
60
  opts
@@ -1,17 +1,35 @@
1
1
  import type { Plugin } from 'vite';
2
+ /**
3
+ * 从远程 Git 仓库拉取 import-map.json 文件,并在构建时注入到 HTML 中的 Vite 插件
4
+ *
5
+ * @export
6
+ * @interface InjectImportMapPluginOptions
7
+ */
2
8
  export interface InjectImportMapPluginOptions {
3
9
  /**
4
10
  * 仓库地址,默认为 https://git.gct-china.com/paas/frontend/gct-paas-cdn.git
11
+ *
12
+ * @type {boolean}
5
13
  */
6
14
  repoUrl?: string;
7
15
  /**
8
16
  * 需要读取的文件路径,默认为 extras/import-map.json
17
+ *
18
+ * @type {boolean}
9
19
  */
10
20
  filePath?: string;
11
21
  /**
12
22
  * 指定分支,若未指定则自动获取当前主工程对应的分支
23
+ *
24
+ * @type {boolean}
13
25
  */
14
26
  branch?: string;
27
+ /**
28
+ * 是否过滤一下只生成使用到的包
29
+ *
30
+ * @type {boolean}
31
+ */
32
+ packageDependencies?: boolean;
15
33
  }
16
34
  /**
17
35
  * 编译时读取并注入 import-map 配置的插件
@@ -6,7 +6,8 @@ const DEV_IMPORT_MAP_PREFIX = ["/plugin-design/@id/", "/plugin-render-mobile/@id
6
6
  export function injectImportMapPlugin(options = {}) {
7
7
  const {
8
8
  repoUrl = "https://git.gct-china.com/paas/frontend/gct-paas-cdn.git",
9
- filePath = "extras/import-map.json"
9
+ filePath = "extras/import-map.json",
10
+ packageDependencies = false
10
11
  } = options;
11
12
  let importMapContent = "{}";
12
13
  return {
@@ -55,6 +56,21 @@ export function injectImportMapPlugin(options = {}) {
55
56
  const rawContent = fs.readFileSync(targetFilePath, "utf-8");
56
57
  try {
57
58
  const parsed = JSON.parse(rawContent);
59
+ if (parsed.imports && packageDependencies) {
60
+ const usedPackages = /* @__PURE__ */ new Set();
61
+ const pkgPath = path.resolve(cwd, "package.json");
62
+ if (fs.existsSync(pkgPath)) {
63
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
64
+ const dependenciesKeys = Object.keys(pkg.dependencies || {});
65
+ dependenciesKeys.forEach((dep) => usedPackages.add(dep));
66
+ Object.keys(parsed.imports).forEach((key) => {
67
+ const pkgName = key.split("/")[0];
68
+ if (!usedPackages.has(pkgName)) {
69
+ delete parsed.imports[key];
70
+ }
71
+ });
72
+ }
73
+ }
58
74
  if (isBuildPluginEnv() && parsed.imports) {
59
75
  const keys = Object.keys(parsed.imports);
60
76
  DEV_IMPORT_MAP_PREFIX.forEach((prefix) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gct-paas/build",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "type": "module",
5
5
  "description": "paas 平台核心包",
6
6
  "main": "dist/index.cjs",