@gct-paas/build 0.1.6-dev.5 → 0.1.6-dev.7

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.
Files changed (35) hide show
  1. package/dist/constants/index.cjs +6 -4
  2. package/dist/util/env-state/env-state.cjs +9 -0
  3. package/dist/util/env-state/env-state.d.ts +7 -0
  4. package/dist/util/index.cjs +7 -0
  5. package/dist/util/index.d.ts +1 -0
  6. package/dist/vite/index.cjs +6 -0
  7. package/dist/vite/index.d.ts +1 -1
  8. package/dist/vite/vite-config/vite-base-config.cjs +7 -4
  9. package/dist/vite/vite-config/vite-config.cjs +5 -8
  10. package/dist/vite/vite-config/vite-pkg-dev-config.cjs +2 -2
  11. package/dist/vite/vite-config/vite-plugin-config.cjs +48 -110
  12. package/dist/vite/vite-config/vite-plugin-config.d.ts +14 -6
  13. package/dist/vite/vite-config/vite-project-config.cjs +2 -1
  14. package/dist/vite/vite-plugins/imnport-external-plugin.cjs +21 -0
  15. package/dist/vite/vite-plugins/imnport-external-plugin.d.ts +16 -0
  16. package/dist/vite/vite-plugins/inject-importmap-plugin.cjs +86 -0
  17. package/dist/vite/vite-plugins/inject-importmap-plugin.d.ts +19 -0
  18. package/es/constants/index.mjs +8 -3
  19. package/es/util/env-state/env-state.d.ts +7 -0
  20. package/es/util/env-state/env-state.mjs +3 -0
  21. package/es/util/index.d.ts +1 -0
  22. package/es/util/index.mjs +1 -0
  23. package/es/vite/index.d.ts +1 -1
  24. package/es/vite/index.mjs +1 -0
  25. package/es/vite/vite-config/vite-base-config.mjs +7 -3
  26. package/es/vite/vite-config/vite-config.mjs +5 -6
  27. package/es/vite/vite-config/vite-pkg-dev-config.mjs +12 -10
  28. package/es/vite/vite-config/vite-plugin-config.d.ts +14 -6
  29. package/es/vite/vite-config/vite-plugin-config.mjs +50 -115
  30. package/es/vite/vite-config/vite-project-config.mjs +3 -1
  31. package/es/vite/vite-plugins/imnport-external-plugin.d.ts +16 -0
  32. package/es/vite/vite-plugins/imnport-external-plugin.mjs +14 -0
  33. package/es/vite/vite-plugins/inject-importmap-plugin.d.ts +19 -0
  34. package/es/vite/vite-plugins/inject-importmap-plugin.mjs +75 -0
  35. package/package.json +5 -4
@@ -10,10 +10,12 @@ const DEFAULT_EXTERNAL = exports.DEFAULT_EXTERNAL = [
10
10
  // vue 相关依赖
11
11
  "vue", "vue-router", "vue-i18n", "pinia",
12
12
  // 第三方依赖
13
- "axios", "dayjs", "lodash-es", "qs", "bignumber.js", "wujie", "sql-formatter", "mqtt", "@fingerprintjs/fingerprintjs", "overlayscrollbars", "@jsplumb/browser-ui", "sortablejs", "interactjs",
13
+ "axios", "dayjs", "lodash-es", "qs", "bignumber.js", "wujie", "@module-federation/runtime", "sql-formatter", "mqtt", "@fingerprintjs/fingerprintjs", "overlayscrollbars", "@jsplumb/browser-ui", "sortablejs", "interactjs", "bwip-js",
14
14
  // 组件库相关依赖
15
- "vuedraggable", "vue-grid-layout", "vant", "ant-design-vue",
15
+ "vuedraggable", "vue-grid-layout", "vant", "ant-design-vue", "vxe-table",
16
16
  // 图标库相关依赖
17
17
  "@ant-design/icons-vue", "@icon-park/vue-next/es/all", "@icon-park/vue-next/icons.json",
18
- // @gct-paas 相关依赖
19
- "@gct-paas/api", "@gct-paas/core", "@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", "@gct-paas/formula-editor", "@gct-paas/platform-icons"];
18
+ // @gct-paas 底包相关依赖
19
+ "@gct-paas/api", "@gct-paas/core", "@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",
20
+ // @gct-paas 独立组件库
21
+ "@gct-paas/platform-icons", "@gct-paas/vue-pdf", "@gct-paas/vue-video-player"];
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isBuildPluginEnv = isBuildPluginEnv;
7
+ function isBuildPluginEnv() {
8
+ return process.env.BUILD_PLUGIN_ENV === "true";
9
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 是否为需要线上插件开发环境
3
+ *
4
+ * @export
5
+ * @return {*} {boolean}
6
+ */
7
+ export declare function isBuildPluginEnv(): boolean;
@@ -15,10 +15,17 @@ Object.defineProperty(exports, "IS_NODE_MODULE", {
15
15
  return _regExp.IS_NODE_MODULE;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "isBuildPluginEnv", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _envState.isBuildPluginEnv;
22
+ }
23
+ });
18
24
  exports.mergeConfig = mergeConfig;
19
25
  exports.unixToWinPath = unixToWinPath;
20
26
  exports.winToUnixPath = winToUnixPath;
21
27
  var _lodashEs = require("lodash-es");
28
+ var _envState = require("./env-state/env-state.cjs");
22
29
  var _regExp = require("./reg-exp/reg-exp.cjs");
23
30
  var _watcher = require("./watcher/watcher.cjs");
24
31
  function winToUnixPath(pathStr) {
@@ -1,3 +1,4 @@
1
+ export { isBuildPluginEnv } from './env-state/env-state';
1
2
  export { IS_NODE_MODULE } from './reg-exp/reg-exp';
2
3
  export { CopyWatch } from './watcher/watcher';
3
4
  /**
@@ -27,6 +27,12 @@ Object.defineProperty(exports, "defineMobilePluginViteConfig", {
27
27
  return _vitePluginConfig.defineMobilePluginViteConfig;
28
28
  }
29
29
  });
30
+ Object.defineProperty(exports, "definePadPluginViteConfig", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _vitePluginConfig.definePadPluginViteConfig;
34
+ }
35
+ });
30
36
  Object.defineProperty(exports, "definePkgDevViteConfig", {
31
37
  enumerable: true,
32
38
  get: function () {
@@ -2,5 +2,5 @@ export { defineViteBaseConfig } from './vite-config/vite-base-config';
2
2
  export { defineViteConfig, defineLoaderViteConfig } from './vite-config/vite-config';
3
3
  export { defineDevViteConfig } from './vite-config/vite-dev-config';
4
4
  export { definePkgDevViteConfig } from './vite-config/vite-pkg-dev-config';
5
- export { definePluginViteConfig, defineDesignPluginViteConfig, defineMobilePluginViteConfig, defineWebPluginViteConfig, } from './vite-config/vite-plugin-config';
5
+ export { definePluginViteConfig, defineDesignPluginViteConfig, defineMobilePluginViteConfig, definePadPluginViteConfig, defineWebPluginViteConfig, } from './vite-config/vite-plugin-config';
6
6
  export { defineProjectViteConfig } from './vite-config/vite-project-config';
@@ -7,7 +7,6 @@ exports.defineViteBaseConfig = defineViteBaseConfig;
7
7
  var _vite = require("vite");
8
8
  var _pluginVue = _interopRequireDefault(require("@vitejs/plugin-vue"));
9
9
  var _pluginVueJsx = _interopRequireDefault(require("@vitejs/plugin-vue-jsx"));
10
- var _vite2 = _interopRequireDefault(require("unocss/vite"));
11
10
  var _path = _interopRequireDefault(require("path"));
12
11
  var _constants = require("../../constants/index.cjs");
13
12
  var _util = require("../../util/index.cjs");
@@ -16,6 +15,11 @@ function defineViteBaseConfig(opts = {}) {
16
15
  const cwd = process.cwd();
17
16
  const outDir = _path.default.resolve(cwd, "dist");
18
17
  return (0, _util.mergeConfig)((0, _vite.defineConfig)({
18
+ resolve: {
19
+ alias: {
20
+ "@": _path.default.resolve(cwd, "./src")
21
+ }
22
+ },
19
23
  css: {
20
24
  preprocessorOptions: {
21
25
  scss: {
@@ -25,12 +29,11 @@ function defineViteBaseConfig(opts = {}) {
25
29
  },
26
30
  build: {
27
31
  outDir,
32
+ target: "chrome89",
28
33
  rolldownOptions: {
29
34
  external: _constants.DEFAULT_EXTERNAL
30
35
  }
31
36
  },
32
- plugins: [(0, _pluginVue.default)(), (0, _pluginVueJsx.default)(), (0, _vite2.default)({
33
- hmrTopLevelAwait: false
34
- })]
37
+ plugins: [(0, _pluginVue.default)(), (0, _pluginVueJsx.default)()]
35
38
  }), opts);
36
39
  }
@@ -7,15 +7,11 @@ exports.defineLoaderViteConfig = defineLoaderViteConfig;
7
7
  exports.defineViteConfig = defineViteConfig;
8
8
  var _vite = require("vite");
9
9
  var _path = _interopRequireDefault(require("path"));
10
- var rf = _interopRequireWildcard(require("rimraf"));
10
+ var _vite2 = _interopRequireDefault(require("unocss/vite"));
11
11
  var _viteBaseConfig = require("./vite-base-config.cjs");
12
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
13
  function defineViteConfig(opts = {}) {
16
14
  const cwd = process.cwd();
17
- const outDir = _path.default.resolve(cwd, "dist");
18
- rf.sync(outDir);
19
15
  return (0, _vite.mergeConfig)((0, _viteBaseConfig.defineViteBaseConfig)((0, _vite.defineConfig)({
20
16
  build: {
21
17
  minify: "terser",
@@ -34,13 +30,14 @@ function defineViteConfig(opts = {}) {
34
30
  cssFileName: "index.min",
35
31
  fileName: "[name].[format].min"
36
32
  }
37
- }
33
+ },
34
+ plugins: [(0, _vite2.default)({
35
+ hmrTopLevelAwait: false
36
+ })]
38
37
  })), opts);
39
38
  }
40
39
  function defineLoaderViteConfig(opts = {}) {
41
40
  const cwd = process.cwd();
42
- const outDir = _path.default.resolve(cwd, "dist");
43
- rf.sync(outDir);
44
41
  return (0, _vite.mergeConfig)(defineViteConfig({
45
42
  build: {
46
43
  lib: {
@@ -80,12 +80,12 @@ function definePkgDevViteConfig(opts = {}) {
80
80
  },
81
81
  // 排除测试目录,以及测试文件
82
82
  exclude: ["**/test/**", "**/*.test.ts", "**/*.test.tsx", "**/*.spec.ts", "**/*.spec.tsx"]
83
- }), (0, _vitePluginStaticCopy.viteStaticCopy)({
83
+ }), ...((0, _fs.existsSync)(_path.default.resolve(cwd, "src/types")) ? [(0, _vitePluginStaticCopy.viteStaticCopy)({
84
84
  targets: [{
85
85
  // 将 src/types 目录下的文件复制到编译输出目录
86
86
  src: "src/types",
87
87
  dest: "."
88
88
  }]
89
- })]
89
+ })] : [])]
90
90
  }), opts);
91
91
  }
@@ -5,140 +5,78 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.defineDesignPluginViteConfig = defineDesignPluginViteConfig;
7
7
  exports.defineMobilePluginViteConfig = defineMobilePluginViteConfig;
8
+ exports.definePadPluginViteConfig = definePadPluginViteConfig;
8
9
  exports.definePluginViteConfig = definePluginViteConfig;
9
10
  exports.defineWebPluginViteConfig = defineWebPluginViteConfig;
10
11
  var _vite = require("vite");
11
12
  var _path = _interopRequireDefault(require("path"));
12
- var _vite2 = require("@module-federation/vite");
13
13
  var _viteBaseConfig = require("./vite-base-config.cjs");
14
14
  var _constants = require("../../constants/index.cjs");
15
+ var _imnportExternalPlugin = require("../vite-plugins/imnport-external-plugin.cjs");
15
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
- const formats = ["es"];
17
- function importMapExternalPlugin(modules) {
18
- return {
19
- name: "vite-plugin-importmap-external",
20
- enforce: "pre",
21
- resolveId(id) {
22
- if (modules.includes(id) || modules.some(m => id.startsWith(m + "/"))) {
23
- return {
24
- id,
25
- external: true
26
- };
27
- }
28
- }
29
- };
30
- }
31
17
  function definePluginViteConfig(opts = {}) {
18
+ const cwd = process.cwd();
19
+ const entry = _path.default.resolve(cwd, "src/index.ts");
20
+ const loaderEntry = _path.default.resolve(cwd, "src/loader.ts");
21
+ const isProd = process.env.NODE_ENV === "production";
32
22
  return (0, _vite.mergeConfig)((0, _viteBaseConfig.defineViteBaseConfig)({
33
- base: "/plugin-design/",
34
- server: {
35
- host: "0.0.0.0",
36
- port: 7001,
37
- allowedHosts: true
38
- },
39
23
  optimizeDeps: {
40
24
  exclude: _constants.DEFAULT_EXTERNAL
41
25
  },
42
- plugins: [importMapExternalPlugin(_constants.DEFAULT_EXTERNAL), {
43
- // Dev 模式:vite:import-analysis 把裸模块改成了 `<base>/@id/<module>`
44
- // 这里再把它还原成裸说明符,让浏览器的 importmap 接管
45
- name: "vite-plugin-importmap-external-dev",
46
- enforce: "post",
47
- apply: "serve",
48
- transform(code) {
49
- return code.replace(/"[^"]*\/@id\/([^"]+)"/g, (match, specifier) => {
50
- const decoded = decodeURIComponent(specifier);
51
- if (_constants.DEFAULT_EXTERNAL.some(m => decoded === m || decoded.startsWith(m + "/"))) {
52
- return `"${decoded}"`;
53
- }
54
- return match;
55
- });
56
- }
57
- }, (0, _vite2.federation)({
58
- name: "gct-paas-plugin",
59
- filename: "remoteEntry.js",
60
- dts: false,
61
- exposes: {
62
- ".": "./src/index.ts"
26
+ build: {
27
+ lib: {
28
+ entry: isProd ? loaderEntry : entry,
29
+ formats: ["es"],
30
+ cssFileName: "index.min",
31
+ fileName: "[name].[format].min"
63
32
  }
64
- })]
33
+ },
34
+ plugins: [...(0, _imnportExternalPlugin.importMapExternalPlugin)(_constants.DEFAULT_EXTERNAL)
35
+ // federation({
36
+ // name: 'gct-paas-plugin',
37
+ // filename: 'remoteEntry.js',
38
+ // dts: false,
39
+ // manifest: true,
40
+ // exposes: {
41
+ // '.': './src/index.ts',
42
+ // },
43
+ // }),
44
+ ]
65
45
  }), opts);
66
46
  }
67
- function formatFileName(format) {
68
- return `[name].${format}.min.js`;
69
- }
70
- function assetFileNames(assetInfo, name) {
71
- if (assetInfo.names.length > 0 && assetInfo.names[0].endsWith(".css")) {
72
- return name + ".min.css";
73
- }
74
- return assetInfo.names[0];
75
- }
76
47
  function defineDesignPluginViteConfig(opts = {}) {
77
- const cwd = process.cwd();
78
- const designEntry = _path.default.resolve(cwd, "src/index.ts");
79
- return (0, _vite.mergeConfig)((0, _viteBaseConfig.defineViteBaseConfig)({
80
- build: {
81
- emptyOutDir: false,
82
- rolldownOptions: {
83
- output: {
84
- assetFileNames: assetInfo => {
85
- return assetFileNames(assetInfo, "design");
86
- }
87
- }
88
- },
89
- lib: {
90
- entry: {
91
- design: designEntry
92
- },
93
- formats,
94
- fileName: formatFileName
95
- }
48
+ return (0, _vite.mergeConfig)(definePluginViteConfig({
49
+ server: {
50
+ port: 7001,
51
+ host: "0.0.0.0",
52
+ allowedHosts: true
96
53
  }
97
54
  }), opts);
98
55
  }
99
56
  function defineMobilePluginViteConfig(opts = {}) {
100
- const cwd = process.cwd();
101
- const mobileEntry = _path.default.resolve(cwd, "src/index.ts");
102
- return (0, _vite.mergeConfig)((0, _viteBaseConfig.defineViteBaseConfig)({
103
- build: {
104
- emptyOutDir: false,
105
- rolldownOptions: {
106
- output: {
107
- assetFileNames: assetInfo => {
108
- return assetFileNames(assetInfo, "mobile");
109
- }
110
- }
111
- },
112
- lib: {
113
- entry: {
114
- mobile: mobileEntry
115
- },
116
- formats,
117
- fileName: formatFileName
118
- }
57
+ return (0, _vite.mergeConfig)(definePluginViteConfig({
58
+ server: {
59
+ port: 7002,
60
+ host: "0.0.0.0",
61
+ allowedHosts: true
62
+ }
63
+ }), opts);
64
+ }
65
+ function definePadPluginViteConfig(opts = {}) {
66
+ return (0, _vite.mergeConfig)(definePluginViteConfig({
67
+ server: {
68
+ port: 7003,
69
+ host: "0.0.0.0",
70
+ allowedHosts: true
119
71
  }
120
72
  }), opts);
121
73
  }
122
74
  function defineWebPluginViteConfig(opts = {}) {
123
- const cwd = process.cwd();
124
- const webEntry = _path.default.resolve(cwd, "src/index.ts");
125
- return (0, _vite.mergeConfig)((0, _viteBaseConfig.defineViteBaseConfig)({
126
- build: {
127
- emptyOutDir: false,
128
- rolldownOptions: {
129
- output: {
130
- assetFileNames: assetInfo => {
131
- return assetFileNames(assetInfo, "web");
132
- }
133
- }
134
- },
135
- lib: {
136
- entry: {
137
- web: webEntry
138
- },
139
- formats,
140
- fileName: formatFileName
141
- }
75
+ return (0, _vite.mergeConfig)(definePluginViteConfig({
76
+ server: {
77
+ port: 7004,
78
+ host: "0.0.0.0",
79
+ allowedHosts: true
142
80
  }
143
81
  }), opts);
144
82
  }
@@ -8,26 +8,34 @@ import { UserConfig } from 'vite';
8
8
  */
9
9
  export declare function definePluginViteConfig(opts?: UserConfig): UserConfig;
10
10
  /**
11
- * 设计端构建配置
11
+ * 设计界面插件构建配置
12
12
  *
13
13
  * @export
14
14
  * @param {UserConfig} [opts={}]
15
- * @returns {*} {UserConfig}
15
+ * @return {*} {UserConfig}
16
16
  */
17
17
  export declare function defineDesignPluginViteConfig(opts?: UserConfig): UserConfig;
18
18
  /**
19
- * 移动端插件构建配置
19
+ * 设计界面插件构建配置
20
20
  *
21
21
  * @export
22
22
  * @param {UserConfig} [opts={}]
23
- * @returns {*} {UserConfig}
23
+ * @return {*} {UserConfig}
24
24
  */
25
25
  export declare function defineMobilePluginViteConfig(opts?: UserConfig): UserConfig;
26
26
  /**
27
- * 网页端插件构建配置
27
+ * 设计界面插件构建配置
28
28
  *
29
29
  * @export
30
30
  * @param {UserConfig} [opts={}]
31
- * @returns {*} {UserConfig}
31
+ * @return {*} {UserConfig}
32
+ */
33
+ export declare function definePadPluginViteConfig(opts?: UserConfig): UserConfig;
34
+ /**
35
+ * 设计界面插件构建配置
36
+ *
37
+ * @export
38
+ * @param {UserConfig} [opts={}]
39
+ * @return {*} {UserConfig}
32
40
  */
33
41
  export declare function defineWebPluginViteConfig(opts?: UserConfig): UserConfig;
@@ -12,6 +12,7 @@ var _path = _interopRequireDefault(require("path"));
12
12
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
13
13
  var _util = require("../../util/index.cjs");
14
14
  var _constants = require("../../constants/index.cjs");
15
+ var _injectImportmapPlugin = require("../vite-plugins/inject-importmap-plugin.cjs");
15
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
17
  function defineProjectViteConfig(opts = {}) {
17
18
  return (0, _vite.defineConfig)(async () => {
@@ -55,7 +56,7 @@ function defineProjectViteConfig(opts = {}) {
55
56
  },
56
57
  plugins: [(0, _pluginVue.default)(), (0, _pluginVueJsx.default)(), (0, _vite2.default)({
57
58
  hmrTopLevelAwait: false
58
- })]
59
+ }), (0, _injectImportmapPlugin.injectImportMapPlugin)()]
59
60
  }, opts);
60
61
  });
61
62
  }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.importMapExternalPlugin = importMapExternalPlugin;
7
+ function importMapExternalPlugin(modules) {
8
+ return [{
9
+ name: "gct-vite-plugin:import-external",
10
+ apply: "serve",
11
+ enforce: "pre",
12
+ resolveId(id) {
13
+ if (modules.includes(id)) {
14
+ return {
15
+ id,
16
+ external: true
17
+ };
18
+ }
19
+ }
20
+ }];
21
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 在 dev 模式下:告诉 Rollup/Rolldown 指定模块是 external
3
+ *
4
+ * @export
5
+ * @param {string[]} modules
6
+ * @return {*}
7
+ */
8
+ export declare function importMapExternalPlugin(modules: string[]): {
9
+ name: string;
10
+ apply: "serve";
11
+ enforce: "pre";
12
+ resolveId(id: string): {
13
+ id: string;
14
+ external: boolean;
15
+ } | undefined;
16
+ }[];
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.injectImportMapPlugin = injectImportMapPlugin;
7
+ var _nodeFs = _interopRequireDefault(require("node:fs"));
8
+ var _nodePath = _interopRequireDefault(require("node:path"));
9
+ var _simpleGit = require("simple-git");
10
+ var _util = require("../../util/index.cjs");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ const DEV_IMPORT_MAP_PREFIX = ["/plugin-kit/@id/", "/plugin-design/@id/", "/plugin-render-mobile/@id/", "/plugin-render-pad/@id/", "/plugin-render-web/@id/"];
13
+ function injectImportMapPlugin(options = {}) {
14
+ const {
15
+ repoUrl = "https://git.gct-china.com/paas/frontend/gct-paas-cdn.git",
16
+ filePath = "extras/import-map.json"
17
+ } = options;
18
+ let importMapContent = "{}";
19
+ return {
20
+ name: "gct-vite-plugin:inject-importmap",
21
+ apply: "build",
22
+ async buildStart() {
23
+ const cwd = process.cwd();
24
+ let targetBranch = options.branch;
25
+ if (!targetBranch) {
26
+ const cwdGit = (0, _simpleGit.simpleGit)(cwd);
27
+ try {
28
+ targetBranch = await cwdGit.revparse(["--abbrev-ref", "HEAD"]);
29
+ } catch (err) {
30
+ this.error(`\u65E0\u6CD5\u81EA\u52A8\u83B7\u53D6\u5F53\u524D git \u5206\u652F\uFF0C\u8BF7\u786E\u8BA4\u5F53\u524D\u5904\u4E8E git \u4ED3\u5E93\u4E2D\uFF0C\u6216\u901A\u8FC7 options.branch \u660E\u786E\u6307\u5B9A\u5206\u652F\u3002\u9519\u8BEF\u4FE1\u606F: ${err}`);
31
+ }
32
+ }
33
+ const cacheDir = _nodePath.default.resolve(cwd, "node_modules/.gct/cache/importmap-repo-cache");
34
+ try {
35
+ if (!_nodeFs.default.existsSync(cacheDir)) {
36
+ _nodeFs.default.mkdirSync(cacheDir, {
37
+ recursive: true
38
+ });
39
+ const git2 = (0, _simpleGit.simpleGit)(cacheDir);
40
+ await git2.init();
41
+ await git2.addRemote("origin", repoUrl);
42
+ await git2.raw(["config", "core.sparseCheckout", "true"]);
43
+ _nodeFs.default.writeFileSync(_nodePath.default.join(cacheDir, ".git/info/sparse-checkout"), filePath);
44
+ }
45
+ const git = (0, _simpleGit.simpleGit)(cacheDir);
46
+ await git.remote(["set-url", "origin", repoUrl]);
47
+ await git.fetch("origin", targetBranch, {
48
+ "--depth": 1
49
+ });
50
+ await git.reset(["--hard", `origin/${targetBranch}`]);
51
+ const targetFilePath = _nodePath.default.join(cacheDir, filePath);
52
+ if (!_nodeFs.default.existsSync(targetFilePath)) {
53
+ this.error(`\u5728\u4ED3\u5E93 ${repoUrl} \u7684 ${targetBranch} \u5206\u652F\u4E2D\uFF0C\u672A\u627E\u5230\u6587\u4EF6: ${filePath}\u3002`);
54
+ }
55
+ const rawContent = _nodeFs.default.readFileSync(targetFilePath, "utf-8");
56
+ try {
57
+ const parsed = JSON.parse(rawContent);
58
+ if ((0, _util.isBuildPluginEnv)() && parsed.imports) {
59
+ const keys = Object.keys(parsed.imports);
60
+ DEV_IMPORT_MAP_PREFIX.forEach(prefix => {
61
+ keys.forEach(key => {
62
+ const val = parsed.imports[key];
63
+ parsed.imports[prefix + key] = val;
64
+ });
65
+ });
66
+ }
67
+ importMapContent = JSON.stringify(parsed);
68
+ } catch (parseError) {
69
+ this.error(`\u76EE\u6807\u6587\u4EF6 ${filePath} \u5305\u542B\u975E\u6CD5\u7684 JSON \u683C\u5F0F: ${parseError}`);
70
+ }
71
+ } catch (error) {
72
+ this.error(`\u4ECE Git \u4ED3\u5E93\u62C9\u53D6\u6216\u8BFB\u53D6 import-map.json \u65F6\u53D1\u751F\u9519\u8BEF: ${error}`);
73
+ }
74
+ },
75
+ transformIndexHtml() {
76
+ return [{
77
+ tag: "script",
78
+ attrs: {
79
+ type: "importmap"
80
+ },
81
+ injectTo: "head-prepend",
82
+ children: importMapContent
83
+ }];
84
+ }
85
+ };
86
+ }
@@ -0,0 +1,19 @@
1
+ import type { Plugin } from 'vite';
2
+ export interface InjectImportMapPluginOptions {
3
+ /**
4
+ * 仓库地址,默认为 https://git.gct-china.com/paas/frontend/gct-paas-cdn.git
5
+ */
6
+ repoUrl?: string;
7
+ /**
8
+ * 需要读取的文件路径,默认为 extras/import-map.json
9
+ */
10
+ filePath?: string;
11
+ /**
12
+ * 指定分支,若未指定则自动获取当前主工程对应的分支
13
+ */
14
+ branch?: string;
15
+ }
16
+ /**
17
+ * 编译时读取并注入 import-map 配置的插件
18
+ */
19
+ export declare function injectImportMapPlugin(options?: InjectImportMapPluginOptions): Plugin;
@@ -13,6 +13,7 @@ export const DEFAULT_EXTERNAL = [
13
13
  "qs",
14
14
  "bignumber.js",
15
15
  "wujie",
16
+ "@module-federation/runtime",
16
17
  "sql-formatter",
17
18
  "mqtt",
18
19
  "@fingerprintjs/fingerprintjs",
@@ -20,16 +21,18 @@ export const DEFAULT_EXTERNAL = [
20
21
  "@jsplumb/browser-ui",
21
22
  "sortablejs",
22
23
  "interactjs",
24
+ "bwip-js",
23
25
  // 组件库相关依赖
24
26
  "vuedraggable",
25
27
  "vue-grid-layout",
26
28
  "vant",
27
29
  "ant-design-vue",
30
+ "vxe-table",
28
31
  // 图标库相关依赖
29
32
  "@ant-design/icons-vue",
30
33
  "@icon-park/vue-next/es/all",
31
34
  "@icon-park/vue-next/icons.json",
32
- // @gct-paas 相关依赖
35
+ // @gct-paas 底包相关依赖
33
36
  "@gct-paas/api",
34
37
  "@gct-paas/core",
35
38
  "@gct-paas/core-mobile",
@@ -45,6 +48,8 @@ export const DEFAULT_EXTERNAL = [
45
48
  "@gct-paas/render-web",
46
49
  "@gct-paas/schema",
47
50
  "@gct-paas/scss",
48
- "@gct-paas/formula-editor",
49
- "@gct-paas/platform-icons"
51
+ // @gct-paas 独立组件库
52
+ "@gct-paas/platform-icons",
53
+ "@gct-paas/vue-pdf",
54
+ "@gct-paas/vue-video-player"
50
55
  ];
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 是否为需要线上插件开发环境
3
+ *
4
+ * @export
5
+ * @return {*} {boolean}
6
+ */
7
+ export declare function isBuildPluginEnv(): boolean;
@@ -0,0 +1,3 @@
1
+ export function isBuildPluginEnv() {
2
+ return process.env.BUILD_PLUGIN_ENV === "true";
3
+ }
@@ -1,3 +1,4 @@
1
+ export { isBuildPluginEnv } from './env-state/env-state';
1
2
  export { IS_NODE_MODULE } from './reg-exp/reg-exp';
2
3
  export { CopyWatch } from './watcher/watcher';
3
4
  /**
package/es/util/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { mergeWith } from "lodash-es";
2
+ export { isBuildPluginEnv } from "./env-state/env-state.mjs";
2
3
  export { IS_NODE_MODULE } from "./reg-exp/reg-exp.mjs";
3
4
  export { CopyWatch } from "./watcher/watcher.mjs";
4
5
  export function winToUnixPath(pathStr) {
@@ -2,5 +2,5 @@ export { defineViteBaseConfig } from './vite-config/vite-base-config';
2
2
  export { defineViteConfig, defineLoaderViteConfig } from './vite-config/vite-config';
3
3
  export { defineDevViteConfig } from './vite-config/vite-dev-config';
4
4
  export { definePkgDevViteConfig } from './vite-config/vite-pkg-dev-config';
5
- export { definePluginViteConfig, defineDesignPluginViteConfig, defineMobilePluginViteConfig, defineWebPluginViteConfig, } from './vite-config/vite-plugin-config';
5
+ export { definePluginViteConfig, defineDesignPluginViteConfig, defineMobilePluginViteConfig, definePadPluginViteConfig, defineWebPluginViteConfig, } from './vite-config/vite-plugin-config';
6
6
  export { defineProjectViteConfig } from './vite-config/vite-project-config';
package/es/vite/index.mjs CHANGED
@@ -6,6 +6,7 @@ export {
6
6
  definePluginViteConfig,
7
7
  defineDesignPluginViteConfig,
8
8
  defineMobilePluginViteConfig,
9
+ definePadPluginViteConfig,
9
10
  defineWebPluginViteConfig
10
11
  } from "./vite-config/vite-plugin-config.mjs";
11
12
  export { defineProjectViteConfig } from "./vite-config/vite-project-config.mjs";
@@ -1,7 +1,6 @@
1
1
  import { defineConfig } from "vite";
2
2
  import vue from "@vitejs/plugin-vue";
3
3
  import vueJsx from "@vitejs/plugin-vue-jsx";
4
- import UnoCSS from "unocss/vite";
5
4
  import path from "path";
6
5
  import { DEFAULT_EXTERNAL } from "../../constants/index.mjs";
7
6
  import { mergeConfig } from "../../util/index.mjs";
@@ -10,6 +9,11 @@ export function defineViteBaseConfig(opts = {}) {
10
9
  const outDir = path.resolve(cwd, "dist");
11
10
  return mergeConfig(
12
11
  defineConfig({
12
+ resolve: {
13
+ alias: {
14
+ "@": path.resolve(cwd, "./src")
15
+ }
16
+ },
13
17
  css: {
14
18
  preprocessorOptions: {
15
19
  scss: {
@@ -19,14 +23,14 @@ export function defineViteBaseConfig(opts = {}) {
19
23
  },
20
24
  build: {
21
25
  outDir,
26
+ target: "chrome89",
22
27
  rolldownOptions: {
23
28
  external: DEFAULT_EXTERNAL
24
29
  }
25
30
  },
26
31
  plugins: [
27
32
  vue(),
28
- vueJsx(),
29
- UnoCSS({ hmrTopLevelAwait: false })
33
+ vueJsx()
30
34
  ]
31
35
  }),
32
36
  opts
@@ -1,11 +1,9 @@
1
1
  import { defineConfig, mergeConfig } from "vite";
2
2
  import path from "path";
3
- import * as rf from "rimraf";
3
+ import UnoCSS from "unocss/vite";
4
4
  import { defineViteBaseConfig } from "./vite-base-config.mjs";
5
5
  export function defineViteConfig(opts = {}) {
6
6
  const cwd = process.cwd();
7
- const outDir = path.resolve(cwd, "dist");
8
- rf.sync(outDir);
9
7
  return mergeConfig(
10
8
  defineViteBaseConfig(
11
9
  defineConfig({
@@ -26,7 +24,10 @@ export function defineViteConfig(opts = {}) {
26
24
  cssFileName: "index.min",
27
25
  fileName: "[name].[format].min"
28
26
  }
29
- }
27
+ },
28
+ plugins: [
29
+ UnoCSS({ hmrTopLevelAwait: false })
30
+ ]
30
31
  })
31
32
  ),
32
33
  opts
@@ -34,8 +35,6 @@ export function defineViteConfig(opts = {}) {
34
35
  }
35
36
  export function defineLoaderViteConfig(opts = {}) {
36
37
  const cwd = process.cwd();
37
- const outDir = path.resolve(cwd, "dist");
38
- rf.sync(outDir);
39
38
  return mergeConfig(
40
39
  defineViteConfig({
41
40
  build: {
@@ -6,7 +6,7 @@ import vueJsx from "@vitejs/plugin-vue-jsx";
6
6
  import { libInjectCss } from "vite-plugin-lib-inject-css";
7
7
  import { viteStaticCopy } from "vite-plugin-static-copy";
8
8
  import dts from "vite-plugin-dts";
9
- import { readFileSync } from "fs";
9
+ import { readFileSync, existsSync } from "fs";
10
10
  import { mergeConfig, IS_NODE_MODULE } from "../../util/index.mjs";
11
11
  import { DEFAULT_EXTERNAL } from "../../constants/index.mjs";
12
12
  export function definePkgDevViteConfig(opts = {}) {
@@ -82,15 +82,17 @@ export function definePkgDevViteConfig(opts = {}) {
82
82
  "**/*.spec.tsx"
83
83
  ]
84
84
  }),
85
- viteStaticCopy({
86
- targets: [
87
- {
88
- // 将 src/types 目录下的文件复制到编译输出目录
89
- src: "src/types",
90
- dest: "."
91
- }
92
- ]
93
- })
85
+ ...existsSync(path.resolve(cwd, "src/types")) ? [
86
+ viteStaticCopy({
87
+ targets: [
88
+ {
89
+ // src/types 目录下的文件复制到编译输出目录
90
+ src: "src/types",
91
+ dest: "."
92
+ }
93
+ ]
94
+ })
95
+ ] : []
94
96
  ]
95
97
  }),
96
98
  opts
@@ -8,26 +8,34 @@ import { UserConfig } from 'vite';
8
8
  */
9
9
  export declare function definePluginViteConfig(opts?: UserConfig): UserConfig;
10
10
  /**
11
- * 设计端构建配置
11
+ * 设计界面插件构建配置
12
12
  *
13
13
  * @export
14
14
  * @param {UserConfig} [opts={}]
15
- * @returns {*} {UserConfig}
15
+ * @return {*} {UserConfig}
16
16
  */
17
17
  export declare function defineDesignPluginViteConfig(opts?: UserConfig): UserConfig;
18
18
  /**
19
- * 移动端插件构建配置
19
+ * 设计界面插件构建配置
20
20
  *
21
21
  * @export
22
22
  * @param {UserConfig} [opts={}]
23
- * @returns {*} {UserConfig}
23
+ * @return {*} {UserConfig}
24
24
  */
25
25
  export declare function defineMobilePluginViteConfig(opts?: UserConfig): UserConfig;
26
26
  /**
27
- * 网页端插件构建配置
27
+ * 设计界面插件构建配置
28
28
  *
29
29
  * @export
30
30
  * @param {UserConfig} [opts={}]
31
- * @returns {*} {UserConfig}
31
+ * @return {*} {UserConfig}
32
+ */
33
+ export declare function definePadPluginViteConfig(opts?: UserConfig): UserConfig;
34
+ /**
35
+ * 设计界面插件构建配置
36
+ *
37
+ * @export
38
+ * @param {UserConfig} [opts={}]
39
+ * @return {*} {UserConfig}
32
40
  */
33
41
  export declare function defineWebPluginViteConfig(opts?: UserConfig): UserConfig;
@@ -1,150 +1,85 @@
1
1
  import { mergeConfig } from "vite";
2
2
  import path from "path";
3
- import { federation } from "@module-federation/vite";
4
3
  import { defineViteBaseConfig } from "./vite-base-config.mjs";
5
4
  import { DEFAULT_EXTERNAL } from "../../constants/index.mjs";
6
- const formats = ["es"];
7
- function importMapExternalPlugin(modules) {
8
- return {
9
- name: "vite-plugin-importmap-external",
10
- enforce: "pre",
11
- resolveId(id) {
12
- if (modules.includes(id) || modules.some((m) => id.startsWith(m + "/"))) {
13
- return { id, external: true };
14
- }
15
- }
16
- };
17
- }
5
+ import { importMapExternalPlugin } from "../vite-plugins/imnport-external-plugin.mjs";
18
6
  export function definePluginViteConfig(opts = {}) {
7
+ const cwd = process.cwd();
8
+ const entry = path.resolve(cwd, "src/index.ts");
9
+ const loaderEntry = path.resolve(cwd, "src/loader.ts");
10
+ const isProd = process.env.NODE_ENV === "production";
19
11
  return mergeConfig(
20
12
  defineViteBaseConfig({
21
- base: "/plugin-design/",
22
- server: {
23
- host: "0.0.0.0",
24
- port: 7001,
25
- allowedHosts: true
26
- },
27
13
  optimizeDeps: {
28
14
  exclude: DEFAULT_EXTERNAL
29
15
  },
16
+ build: {
17
+ lib: {
18
+ entry: isProd ? loaderEntry : entry,
19
+ formats: ["es"],
20
+ cssFileName: "index.min",
21
+ fileName: "[name].[format].min"
22
+ }
23
+ },
30
24
  plugins: [
31
- importMapExternalPlugin(DEFAULT_EXTERNAL),
32
- {
33
- // Dev 模式:vite:import-analysis 把裸模块改成了 `<base>/@id/<module>`
34
- // 这里再把它还原成裸说明符,让浏览器的 importmap 接管
35
- name: "vite-plugin-importmap-external-dev",
36
- enforce: "post",
37
- apply: "serve",
38
- transform(code) {
39
- return code.replace(
40
- /"[^"]*\/@id\/([^"]+)"/g,
41
- (match, specifier) => {
42
- const decoded = decodeURIComponent(specifier);
43
- if (DEFAULT_EXTERNAL.some(
44
- (m) => decoded === m || decoded.startsWith(m + "/")
45
- )) {
46
- return `"${decoded}"`;
47
- }
48
- return match;
49
- }
50
- );
51
- }
52
- },
53
- federation({
54
- name: "gct-paas-plugin",
55
- filename: "remoteEntry.js",
56
- dts: false,
57
- exposes: {
58
- ".": "./src/index.ts"
59
- }
60
- })
25
+ ...importMapExternalPlugin(DEFAULT_EXTERNAL)
26
+ // federation({
27
+ // name: 'gct-paas-plugin',
28
+ // filename: 'remoteEntry.js',
29
+ // dts: false,
30
+ // manifest: true,
31
+ // exposes: {
32
+ // '.': './src/index.ts',
33
+ // },
34
+ // }),
61
35
  ]
62
36
  }),
63
37
  opts
64
38
  );
65
39
  }
66
- function formatFileName(format) {
67
- return `[name].${format}.min.js`;
68
- }
69
- function assetFileNames(assetInfo, name) {
70
- if (assetInfo.names.length > 0 && assetInfo.names[0].endsWith(".css")) {
71
- return name + ".min.css";
72
- }
73
- return assetInfo.names[0];
74
- }
75
40
  export function defineDesignPluginViteConfig(opts = {}) {
76
- const cwd = process.cwd();
77
- const designEntry = path.resolve(cwd, "src/index.ts");
78
41
  return mergeConfig(
79
- defineViteBaseConfig({
80
- build: {
81
- emptyOutDir: false,
82
- rolldownOptions: {
83
- output: {
84
- assetFileNames: (assetInfo) => {
85
- return assetFileNames(assetInfo, "design");
86
- }
87
- }
88
- },
89
- lib: {
90
- entry: {
91
- design: designEntry
92
- },
93
- formats,
94
- fileName: formatFileName
95
- }
42
+ definePluginViteConfig({
43
+ server: {
44
+ port: 7001,
45
+ host: "0.0.0.0",
46
+ allowedHosts: true
96
47
  }
97
48
  }),
98
49
  opts
99
50
  );
100
51
  }
101
52
  export function defineMobilePluginViteConfig(opts = {}) {
102
- const cwd = process.cwd();
103
- const mobileEntry = path.resolve(cwd, "src/index.ts");
104
53
  return mergeConfig(
105
- defineViteBaseConfig({
106
- build: {
107
- emptyOutDir: false,
108
- rolldownOptions: {
109
- output: {
110
- assetFileNames: (assetInfo) => {
111
- return assetFileNames(assetInfo, "mobile");
112
- }
113
- }
114
- },
115
- lib: {
116
- entry: {
117
- mobile: mobileEntry
118
- },
119
- formats,
120
- fileName: formatFileName
121
- }
54
+ definePluginViteConfig({
55
+ server: {
56
+ port: 7002,
57
+ host: "0.0.0.0",
58
+ allowedHosts: true
59
+ }
60
+ }),
61
+ opts
62
+ );
63
+ }
64
+ export function definePadPluginViteConfig(opts = {}) {
65
+ return mergeConfig(
66
+ definePluginViteConfig({
67
+ server: {
68
+ port: 7003,
69
+ host: "0.0.0.0",
70
+ allowedHosts: true
122
71
  }
123
72
  }),
124
73
  opts
125
74
  );
126
75
  }
127
76
  export function defineWebPluginViteConfig(opts = {}) {
128
- const cwd = process.cwd();
129
- const webEntry = path.resolve(cwd, "src/index.ts");
130
77
  return mergeConfig(
131
- defineViteBaseConfig({
132
- build: {
133
- emptyOutDir: false,
134
- rolldownOptions: {
135
- output: {
136
- assetFileNames: (assetInfo) => {
137
- return assetFileNames(assetInfo, "web");
138
- }
139
- }
140
- },
141
- lib: {
142
- entry: {
143
- web: webEntry
144
- },
145
- formats,
146
- fileName: formatFileName
147
- }
78
+ definePluginViteConfig({
79
+ server: {
80
+ port: 7004,
81
+ host: "0.0.0.0",
82
+ allowedHosts: true
148
83
  }
149
84
  }),
150
85
  opts
@@ -8,6 +8,7 @@ import path from "path";
8
8
  import fse from "fs-extra";
9
9
  import { mergeConfig } from "../../util/index.mjs";
10
10
  import { DEFAULT_EXTERNAL } from "../../constants/index.mjs";
11
+ import { injectImportMapPlugin } from "../vite-plugins/inject-importmap-plugin.mjs";
11
12
  export function defineProjectViteConfig(opts = {}) {
12
13
  return defineConfig(async () => {
13
14
  const cwd = process.cwd();
@@ -52,7 +53,8 @@ export function defineProjectViteConfig(opts = {}) {
52
53
  plugins: [
53
54
  vue(),
54
55
  vueJsx(),
55
- UnoCSS({ hmrTopLevelAwait: false })
56
+ UnoCSS({ hmrTopLevelAwait: false }),
57
+ injectImportMapPlugin()
56
58
  ]
57
59
  },
58
60
  opts
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 在 dev 模式下:告诉 Rollup/Rolldown 指定模块是 external
3
+ *
4
+ * @export
5
+ * @param {string[]} modules
6
+ * @return {*}
7
+ */
8
+ export declare function importMapExternalPlugin(modules: string[]): {
9
+ name: string;
10
+ apply: "serve";
11
+ enforce: "pre";
12
+ resolveId(id: string): {
13
+ id: string;
14
+ external: boolean;
15
+ } | undefined;
16
+ }[];
@@ -0,0 +1,14 @@
1
+ export function importMapExternalPlugin(modules) {
2
+ return [
3
+ {
4
+ name: "gct-vite-plugin:import-external",
5
+ apply: "serve",
6
+ enforce: "pre",
7
+ resolveId(id) {
8
+ if (modules.includes(id)) {
9
+ return { id, external: true };
10
+ }
11
+ }
12
+ }
13
+ ];
14
+ }
@@ -0,0 +1,19 @@
1
+ import type { Plugin } from 'vite';
2
+ export interface InjectImportMapPluginOptions {
3
+ /**
4
+ * 仓库地址,默认为 https://git.gct-china.com/paas/frontend/gct-paas-cdn.git
5
+ */
6
+ repoUrl?: string;
7
+ /**
8
+ * 需要读取的文件路径,默认为 extras/import-map.json
9
+ */
10
+ filePath?: string;
11
+ /**
12
+ * 指定分支,若未指定则自动获取当前主工程对应的分支
13
+ */
14
+ branch?: string;
15
+ }
16
+ /**
17
+ * 编译时读取并注入 import-map 配置的插件
18
+ */
19
+ export declare function injectImportMapPlugin(options?: InjectImportMapPluginOptions): Plugin;
@@ -0,0 +1,75 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { simpleGit } from "simple-git";
4
+ import { isBuildPluginEnv } from "../../util/index.mjs";
5
+ const DEV_IMPORT_MAP_PREFIX = ["/plugin-kit/@id/", "/plugin-design/@id/", "/plugin-render-mobile/@id/", "/plugin-render-pad/@id/", "/plugin-render-web/@id/"];
6
+ export function injectImportMapPlugin(options = {}) {
7
+ const {
8
+ repoUrl = "https://git.gct-china.com/paas/frontend/gct-paas-cdn.git",
9
+ filePath = "extras/import-map.json"
10
+ } = options;
11
+ let importMapContent = "{}";
12
+ return {
13
+ name: "gct-vite-plugin:inject-importmap",
14
+ apply: "build",
15
+ async buildStart() {
16
+ const cwd = process.cwd();
17
+ let targetBranch = options.branch;
18
+ if (!targetBranch) {
19
+ const cwdGit = simpleGit(cwd);
20
+ try {
21
+ targetBranch = await cwdGit.revparse(["--abbrev-ref", "HEAD"]);
22
+ } catch (err) {
23
+ this.error(`\u65E0\u6CD5\u81EA\u52A8\u83B7\u53D6\u5F53\u524D git \u5206\u652F\uFF0C\u8BF7\u786E\u8BA4\u5F53\u524D\u5904\u4E8E git \u4ED3\u5E93\u4E2D\uFF0C\u6216\u901A\u8FC7 options.branch \u660E\u786E\u6307\u5B9A\u5206\u652F\u3002\u9519\u8BEF\u4FE1\u606F: ${err}`);
24
+ }
25
+ }
26
+ const cacheDir = path.resolve(cwd, "node_modules/.gct/cache/importmap-repo-cache");
27
+ try {
28
+ if (!fs.existsSync(cacheDir)) {
29
+ fs.mkdirSync(cacheDir, { recursive: true });
30
+ const git2 = simpleGit(cacheDir);
31
+ await git2.init();
32
+ await git2.addRemote("origin", repoUrl);
33
+ await git2.raw(["config", "core.sparseCheckout", "true"]);
34
+ fs.writeFileSync(path.join(cacheDir, ".git/info/sparse-checkout"), filePath);
35
+ }
36
+ const git = simpleGit(cacheDir);
37
+ await git.remote(["set-url", "origin", repoUrl]);
38
+ await git.fetch("origin", targetBranch, { "--depth": 1 });
39
+ await git.reset(["--hard", `origin/${targetBranch}`]);
40
+ const targetFilePath = path.join(cacheDir, filePath);
41
+ if (!fs.existsSync(targetFilePath)) {
42
+ this.error(`\u5728\u4ED3\u5E93 ${repoUrl} \u7684 ${targetBranch} \u5206\u652F\u4E2D\uFF0C\u672A\u627E\u5230\u6587\u4EF6: ${filePath}\u3002`);
43
+ }
44
+ const rawContent = fs.readFileSync(targetFilePath, "utf-8");
45
+ try {
46
+ const parsed = JSON.parse(rawContent);
47
+ if (isBuildPluginEnv() && parsed.imports) {
48
+ const keys = Object.keys(parsed.imports);
49
+ DEV_IMPORT_MAP_PREFIX.forEach((prefix) => {
50
+ keys.forEach((key) => {
51
+ const val = parsed.imports[key];
52
+ parsed.imports[prefix + key] = val;
53
+ });
54
+ });
55
+ }
56
+ importMapContent = JSON.stringify(parsed);
57
+ } catch (parseError) {
58
+ this.error(`\u76EE\u6807\u6587\u4EF6 ${filePath} \u5305\u542B\u975E\u6CD5\u7684 JSON \u683C\u5F0F: ${parseError}`);
59
+ }
60
+ } catch (error) {
61
+ this.error(`\u4ECE Git \u4ED3\u5E93\u62C9\u53D6\u6216\u8BFB\u53D6 import-map.json \u65F6\u53D1\u751F\u9519\u8BEF: ${error}`);
62
+ }
63
+ },
64
+ transformIndexHtml() {
65
+ return [
66
+ {
67
+ tag: "script",
68
+ attrs: { type: "importmap" },
69
+ injectTo: "head-prepend",
70
+ children: importMapContent
71
+ }
72
+ ];
73
+ }
74
+ };
75
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gct-paas/build",
3
- "version": "0.1.6-dev.5",
3
+ "version": "0.1.6-dev.7",
4
4
  "type": "module",
5
5
  "description": "paas 平台核心包",
6
6
  "main": "dist/index.cjs",
@@ -43,7 +43,7 @@
43
43
  "@commitlint/config-conventional": "^20.4.4",
44
44
  "@eslint/config-helpers": "^0.5.3",
45
45
  "@eslint/js": "^9.39.4",
46
- "@gct-paas/scss": "^0.1.5",
46
+ "@gct-paas/scss": "latest",
47
47
  "@inquirer/prompts": "^8.3.0",
48
48
  "@module-federation/vite": "^1.13.0",
49
49
  "@vitejs/plugin-vue": "^6.0.5",
@@ -71,13 +71,14 @@
71
71
  "prettier": "^3.8.1",
72
72
  "rimraf": "^6.1.3",
73
73
  "sass": "^1.98.0",
74
+ "simple-git": "^3.33.0",
74
75
  "stylelint": "~16.26.1",
75
76
  "stylelint-config-recess-order": "~7.4.0",
76
77
  "stylelint-config-standard-scss": "~16.0.0",
77
78
  "stylelint-scss": "~6.14.0",
78
79
  "typescript-eslint": "^8.57.0",
79
80
  "unocss": "66.6.6",
80
- "vite": "^8.0.0",
81
+ "vite": "^8.0.1",
81
82
  "vite-plugin-dts": "^4.5.4",
82
83
  "vite-plugin-lib-inject-css": "^2.2.2",
83
84
  "vite-plugin-static-copy": "^3.3.0",
@@ -99,5 +100,5 @@
99
100
  "peerDependencies": {
100
101
  "@gct-paas/scss": "*"
101
102
  },
102
- "gitHead": "6385e29b22a78c9971112aa313aa5c4154b8d0e5"
103
+ "gitHead": "ea800dfadead2fc20cf424513bc776a340e50ee8"
103
104
  }