@vc-shell/config-generator 1.2.4-beta.8 → 2.0.0-alpha.0
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 +49 -104
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/templates/shared-deps.d.ts +23 -0
- package/dist/templates/shared-deps.d.ts.map +1 -0
- package/dist/templates/shared-deps.js +33 -0
- package/dist/templates/shared-deps.js.map +1 -0
- package/dist/templates/vite.dynamic-module.appconfig.d.ts +3 -15
- package/dist/templates/vite.dynamic-module.appconfig.d.ts.map +1 -1
- package/dist/templates/vite.dynamic-module.appconfig.js +62 -166
- package/dist/templates/vite.dynamic-module.appconfig.js.map +1 -1
- package/dist/templates/vite.dynamic-module.appconfig.test.d.ts +2 -0
- package/dist/templates/vite.dynamic-module.appconfig.test.d.ts.map +1 -0
- package/dist/templates/vite.dynamic-module.appconfig.test.js +60 -0
- package/dist/templates/vite.dynamic-module.appconfig.test.js.map +1 -0
- package/dist/templates/vite.host.appconfig.d.ts +32 -0
- package/dist/templates/vite.host.appconfig.d.ts.map +1 -0
- package/dist/templates/vite.host.appconfig.js +42 -0
- package/dist/templates/vite.host.appconfig.js.map +1 -0
- package/dist/templates/vite.host.appconfig.test.d.ts +2 -0
- package/dist/templates/vite.host.appconfig.test.d.ts.map +1 -0
- package/dist/templates/vite.host.appconfig.test.js +51 -0
- package/dist/templates/vite.host.appconfig.test.js.map +1 -0
- package/dist/types.d.ts +7 -18
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -3
- package/dist/templates/external.d.ts +0 -7
- package/dist/templates/external.d.ts.map +0 -1
- package/dist/templates/external.js +0 -24
- package/dist/templates/external.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,145 +1,90 @@
|
|
|
1
1
|
# VC-Shell Vite Configuration Generator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Pre-configured Vite configurations for VC-Shell projects.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @vc-shell/config-generator --save-dev
|
|
9
|
-
# or
|
|
10
8
|
yarn add -D @vc-shell/config-generator
|
|
11
9
|
```
|
|
12
10
|
|
|
13
11
|
## Available Configurations
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
### Application Configuration
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
2. **Library Configuration** - for creating libraries and packages
|
|
19
|
-
3. **Dynamic Modules Configuration** - for creating modules that can be loaded dynamically at runtime
|
|
15
|
+
For primary VC-Shell applications (e.g., vendor-portal).
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
```typescript
|
|
18
|
+
// vite.config.ts
|
|
19
|
+
import { getApplicationConfiguration } from "@vc-shell/config-generator";
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
export default getApplicationConfiguration();
|
|
22
|
+
```
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
// vite.config.js
|
|
27
|
-
import { getApplicationConfiguration } from '@vc-shell/config-generator';
|
|
24
|
+
### Host Federation Configuration
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
// Custom settings (optional)
|
|
31
|
-
});
|
|
32
|
-
```
|
|
26
|
+
Adds Module Federation to a host application. Merge with your application config:
|
|
33
27
|
|
|
34
|
-
|
|
28
|
+
```typescript
|
|
29
|
+
import { getApplicationConfiguration, getHostFederationConfig } from "@vc-shell/config-generator";
|
|
30
|
+
import { mergeConfig } from "vite";
|
|
31
|
+
|
|
32
|
+
export default mergeConfig(
|
|
33
|
+
getApplicationConfiguration(),
|
|
34
|
+
getHostFederationConfig(),
|
|
35
|
+
);
|
|
36
|
+
```
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
// vite.config.js
|
|
38
|
-
import { getLibraryConfiguration } from '@vc-shell/config-generator';
|
|
38
|
+
Custom shared dependencies:
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
```typescript
|
|
41
|
+
getHostFederationConfig({
|
|
42
|
+
sharedDeps: { "my-lib": { singleton: true } },
|
|
42
43
|
});
|
|
43
44
|
```
|
|
44
45
|
|
|
45
|
-
### Dynamic
|
|
46
|
+
### Dynamic Module Configuration (Remote)
|
|
47
|
+
|
|
48
|
+
For modules loaded at runtime via Module Federation.
|
|
46
49
|
|
|
47
|
-
```
|
|
48
|
-
// vite.config.
|
|
49
|
-
import { getDynamicModuleConfiguration } from
|
|
50
|
+
```typescript
|
|
51
|
+
// vite.config.ts
|
|
52
|
+
import { getDynamicModuleConfiguration } from "@vc-shell/config-generator";
|
|
50
53
|
|
|
51
54
|
export default getDynamicModuleConfiguration({
|
|
52
|
-
// Compatibility configuration is required
|
|
53
55
|
compatibility: {
|
|
54
|
-
|
|
55
|
-
framework: '^1.1.0',
|
|
56
|
-
|
|
57
|
-
// Compatibility with other modules (optional)
|
|
58
|
-
modules: {
|
|
59
|
-
'@vc-shell/module-catalog': '^1.0.0'
|
|
60
|
-
},
|
|
61
|
-
|
|
56
|
+
framework: "^2.0.0",
|
|
62
57
|
},
|
|
63
|
-
|
|
64
|
-
// Additional configuration options (optional)
|
|
65
|
-
entry: './src/index.ts',
|
|
66
|
-
outDir: 'dist/modules',
|
|
67
|
-
moduleName: 'MyCustomModule',
|
|
68
|
-
|
|
69
|
-
// Additional external dependencies
|
|
70
|
-
externals: ['axios', 'chart.js']
|
|
71
58
|
});
|
|
72
59
|
```
|
|
73
60
|
|
|
74
|
-
|
|
61
|
+
| Option | Type | Default | Description |
|
|
62
|
+
|--------|------|---------|-------------|
|
|
63
|
+
| `entry` | `string` | `"./src/modules/index.ts"` | Module entry point |
|
|
64
|
+
| `exposes` | `Record<string, string>` | `{ "./module": entry }` | MF exposes map |
|
|
65
|
+
| `compatibility.framework` | `string` | -- | Compatible framework semver range |
|
|
66
|
+
| `compatibility.modules` | `Record<string, string>` | -- | Compatible module version ranges |
|
|
75
67
|
|
|
76
|
-
|
|
77
|
-
|--------|------|-------------|
|
|
78
|
-
| `entry` | `string` | Module entry point (default: `./index.ts`) |
|
|
79
|
-
| `outDir` | `string` | Output directory (default: `dist/packages/modules`) |
|
|
80
|
-
| `moduleName` | `string` | Module name for UMD build (default: derived from package.json) |
|
|
81
|
-
| `compatibility` | `object` | **Required:** Compatibility constraints for the module |
|
|
82
|
-
| `compatibility.framework` | `string` | **Required:** Compatible framework version range |
|
|
83
|
-
| `compatibility.modules` | `object` | Compatible version ranges for other modules |
|
|
84
|
-
| `externals` | `string[]` | Additional external dependencies |
|
|
68
|
+
The module produces a `remoteEntry.js` file that the host loads at runtime.
|
|
85
69
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
### Version Metadata
|
|
89
|
-
|
|
90
|
-
The configuration automatically adds version and compatibility information to the module build:
|
|
91
|
-
|
|
92
|
-
1. Adds a global variable `window.__VC_SHELL_MODULE_VERSION_INFO__` with version information
|
|
93
|
-
2. Creates a `version.json` file with version and compatibility metadata
|
|
94
|
-
3. Updates `manifest.json`, adding a reference to the version file
|
|
95
|
-
|
|
96
|
-
### Output Format
|
|
70
|
+
### Library Configuration
|
|
97
71
|
|
|
98
|
-
|
|
72
|
+
For creating reusable packages.
|
|
99
73
|
|
|
100
|
-
|
|
74
|
+
```typescript
|
|
75
|
+
import { getLibraryConfiguration } from "@vc-shell/config-generator";
|
|
101
76
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
- Vue Router
|
|
105
|
-
- Vee-Validate
|
|
106
|
-
- Vue I18n
|
|
107
|
-
- Moment.js
|
|
108
|
-
- Lodash
|
|
109
|
-
- VueUse
|
|
110
|
-
- VC-Shell Framework
|
|
77
|
+
export default getLibraryConfiguration();
|
|
78
|
+
```
|
|
111
79
|
|
|
112
|
-
|
|
80
|
+
### Modules Library Configuration
|
|
113
81
|
|
|
114
|
-
|
|
82
|
+
For building a library of statically-bundled modules.
|
|
115
83
|
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
import { getDynamicModuleConfiguration } from '@vc-shell/config-generator';
|
|
84
|
+
```typescript
|
|
85
|
+
import { getModulesLibraryConfiguration } from "@vc-shell/config-generator";
|
|
119
86
|
|
|
120
|
-
export default
|
|
121
|
-
entry:
|
|
122
|
-
outDir: 'dist/custom-module',
|
|
123
|
-
moduleName: 'VcCustomModule',
|
|
124
|
-
|
|
125
|
-
compatibility: {
|
|
126
|
-
framework: '^1.2.0',
|
|
127
|
-
modules: {
|
|
128
|
-
'@vc-shell/module-catalog': '^1.0.0',
|
|
129
|
-
'@vc-shell/module-auth': '^1.5.0'
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
externals: [
|
|
134
|
-
'axios',
|
|
135
|
-
'chart.js'
|
|
136
|
-
],
|
|
137
|
-
|
|
138
|
-
// Any additional Vite configuration options
|
|
139
|
-
build: {
|
|
140
|
-
minify: 'esbuild',
|
|
141
|
-
sourcemap: true,
|
|
142
|
-
chunkSizeWarningLimit: 800
|
|
143
|
-
}
|
|
87
|
+
export default getModulesLibraryConfiguration({
|
|
88
|
+
entry: "./index.ts",
|
|
144
89
|
});
|
|
145
90
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UserConfig } from "vite";
|
|
2
|
+
import { getHostFederationConfig } from "./templates/vite.host.appconfig.js";
|
|
2
3
|
import type { ModulesLibraryOptions } from "./templates/vite.modules-library.appconfig.js";
|
|
3
4
|
import { DynamicModuleOptions } from "./types.js";
|
|
4
5
|
declare function getLibraryConfiguration(options?: UserConfig): Record<string, any>;
|
|
@@ -26,5 +27,6 @@ declare function getDynamicModuleConfiguration(options: DynamicModuleOptions): R
|
|
|
26
27
|
declare function getModulesLibraryConfiguration(options?: ModulesLibraryOptions): Record<string, any>;
|
|
27
28
|
export type { DynamicModuleOptions, CompatibilityOptions } from "./types.js";
|
|
28
29
|
export type { ModulesLibraryOptions } from "./templates/vite.modules-library.appconfig.js";
|
|
29
|
-
export {
|
|
30
|
+
export type { HostFederationOptions } from "./templates/vite.host.appconfig.js";
|
|
31
|
+
export { getLibraryConfiguration, getApplicationConfiguration, getDynamicModuleConfiguration, getModulesLibraryConfiguration, getHostFederationConfig };
|
|
30
32
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,UAAU,EAAgB,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,UAAU,EAAgB,MAAM,MAAM,CAAC;AAK7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,4CAA4C,CAAC;AAErF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uDAAuD,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAM1D,iBAAS,uBAAuB,CAAC,OAAO,GAAE,UAAe,uBAGxD;AAED,iBAAS,2BAA2B,CAAC,OAAO,GAAE,UAAe,uBAG5D;AAqDD;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,6BAA6B,CAAC,OAAO,EAAE,oBAAoB,uBASnE;AAED,iBAAS,8BAA8B,CAAC,OAAO,GAAE,qBAA0B,uBAI1E;AAED,YAAY,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACrF,YAAY,EAAE,qBAAqB,EAAE,MAAM,uDAAuD,CAAC;AACnG,YAAY,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AAExF,OAAO,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,6BAA6B,EAAE,8BAA8B,EAAE,uBAAuB,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { readFileSync } from "node:fs";
|
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { cwd } from "node:process";
|
|
8
8
|
import dynamicModuleConfiguration from "./templates/vite.dynamic-module.appconfig.js";
|
|
9
|
+
import { getHostFederationConfig } from "./templates/vite.host.appconfig.js";
|
|
9
10
|
import modulesLibraryConfiguration from "./templates/vite.modules-library.appconfig.js";
|
|
10
11
|
const packageJson = fs.readFileSync(cwd() + "/package.json");
|
|
11
12
|
const name = JSON.parse(packageJson.toString()).name;
|
|
@@ -93,5 +94,5 @@ function getModulesLibraryConfiguration(options = {}) {
|
|
|
93
94
|
const baseConfig = modulesLibraryConfiguration(options);
|
|
94
95
|
return mergeConfig(baseConfig, options);
|
|
95
96
|
}
|
|
96
|
-
export { getLibraryConfiguration, getApplicationConfiguration, getDynamicModuleConfiguration, getModulesLibraryConfiguration };
|
|
97
|
+
export { getLibraryConfiguration, getApplicationConfiguration, getDynamicModuleConfiguration, getModulesLibraryConfiguration, getHostFederationConfig };
|
|
97
98
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,wBAAwB,MAAM,mDAAmD,CAAC;AACzF,OAAO,oBAAoB,MAAM,+CAA+C,CAAC;AACjF,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,WAAW,EAA4B,MAAM,MAAM,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAW,IAAI,EAAW,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,0BAA0B,MAAM,sDAAsD,CAAC;AAC9F,OAAO,2BAA2B,MAAM,uDAAuD,CAAC;AAIhG,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,eAAe,CAAC,CAAC;AAC7D,MAAM,IAAI,GA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6BAA6B,CAAC,OAA6B;IAClE,OAAO,CAAC,GAAG,CAAC,uCAAuC,EAAE,OAAO,CAAC,CAAC;IAC9D,MAAM,GAAG,GAAG,cAAc,EAAE,CAAC;IAC7B,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IACtB,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;IAC5B,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,IAAI,OAAO,EAAE,CAAC,CAAC;IAE1C,MAAM,UAAU,GAAG,0BAA0B,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5D,OAAO,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,8BAA8B,CAAC,UAAiC,EAAE;IACzE,OAAO,CAAC,GAAG,CAAC,4BAA4B,IAAI,MAAM,OAAO,MAAM,CAAC,CAAC;IACjE,MAAM,UAAU,GAAG,2BAA2B,CAAC,OAAO,CAAC,CAAC;IACxD,OAAO,WAAW,CAAC,UAAU,EAAE,OAAqB,CAAC,CAAC;AACxD,CAAC;AAMD,OAAO,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,6BAA6B,EAAE,8BAA8B,EAAE,uBAAuB,EAAE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface SharedDepConfig {
|
|
2
|
+
singleton?: boolean;
|
|
3
|
+
requiredVersion?: string;
|
|
4
|
+
eager?: boolean;
|
|
5
|
+
import?: false | string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Canonical list of shared dependency names.
|
|
9
|
+
* This is the SINGLE SOURCE OF TRUTH — loader-mf.ts imports this
|
|
10
|
+
* to build its runtime shared config, ensuring build and runtime stay in sync.
|
|
11
|
+
*/
|
|
12
|
+
export declare const SHARED_DEP_NAMES: ReadonlyArray<"vue" | "vue-router" | "vue-i18n" | "vee-validate" | "lodash-es" | "@vueuse/core" | "@vc-shell/framework">;
|
|
13
|
+
/**
|
|
14
|
+
* Shared deps for HOST app — bundles all deps (provides them to remotes).
|
|
15
|
+
*/
|
|
16
|
+
export declare const DEFAULT_SHARED: Record<string, SharedDepConfig>;
|
|
17
|
+
/**
|
|
18
|
+
* Shared deps for REMOTE modules — `import: false` prevents bundling fallback chunks.
|
|
19
|
+
* The remote relies entirely on the host to provide these deps at runtime.
|
|
20
|
+
* This eliminates multi-MB fallback bundles (vue, framework, lodash, etc).
|
|
21
|
+
*/
|
|
22
|
+
export declare const REMOTE_SHARED: Record<string, SharedDepConfig>;
|
|
23
|
+
//# sourceMappingURL=shared-deps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-deps.d.ts","sourceRoot":"","sources":["../../src/templates/shared-deps.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CACzB;AAgBD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAoC,aAAa,CAC5E,KAAK,GAAG,YAAY,GAAG,UAAU,GAAG,cAAc,GAAG,WAAW,GAAG,cAAc,GAAG,qBAAqB,CAC1G,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAA2B,CAAC;AAEvF;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAKzD,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base shared dependency definitions for Module Federation.
|
|
3
|
+
* Both host and remote use the same dep list with singleton negotiation.
|
|
4
|
+
*/
|
|
5
|
+
const SHARED_DEPS_BASE = {
|
|
6
|
+
vue: { singleton: true, requiredVersion: "^3.4.0" },
|
|
7
|
+
"vue-router": { singleton: true, requiredVersion: "^4.0.0" },
|
|
8
|
+
"vue-i18n": { singleton: true, requiredVersion: "^9.0.0" },
|
|
9
|
+
"vee-validate": { singleton: true },
|
|
10
|
+
"lodash-es": { singleton: true },
|
|
11
|
+
"@vueuse/core": { singleton: true },
|
|
12
|
+
"@vc-shell/framework": { singleton: true },
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Canonical list of shared dependency names.
|
|
16
|
+
* This is the SINGLE SOURCE OF TRUTH — loader-mf.ts imports this
|
|
17
|
+
* to build its runtime shared config, ensuring build and runtime stay in sync.
|
|
18
|
+
*/
|
|
19
|
+
export const SHARED_DEP_NAMES = Object.keys(SHARED_DEPS_BASE);
|
|
20
|
+
/**
|
|
21
|
+
* Shared deps for HOST app — bundles all deps (provides them to remotes).
|
|
22
|
+
*/
|
|
23
|
+
export const DEFAULT_SHARED = { ...SHARED_DEPS_BASE };
|
|
24
|
+
/**
|
|
25
|
+
* Shared deps for REMOTE modules — `import: false` prevents bundling fallback chunks.
|
|
26
|
+
* The remote relies entirely on the host to provide these deps at runtime.
|
|
27
|
+
* This eliminates multi-MB fallback bundles (vue, framework, lodash, etc).
|
|
28
|
+
*/
|
|
29
|
+
export const REMOTE_SHARED = Object.fromEntries(Object.entries(SHARED_DEPS_BASE).map(([key, config]) => [
|
|
30
|
+
key,
|
|
31
|
+
{ ...config, import: false },
|
|
32
|
+
]));
|
|
33
|
+
//# sourceMappingURL=shared-deps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-deps.js","sourceRoot":"","sources":["../../src/templates/shared-deps.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,MAAM,gBAAgB,GAAoD;IACxE,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE;IACnD,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE;IAC5D,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE;IAC1D,cAAc,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE;IACnC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE;IAChC,cAAc,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE;IACnC,qBAAqB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE;CAC3C,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAE3D,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAoC,EAAE,GAAG,gBAAgB,EAAE,CAAC;AAEvF;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAoC,MAAM,CAAC,WAAW,CAC9E,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;IACtD,GAAG;IACH,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,KAAc,EAAE;CACtC,CAAC,CACH,CAAC"}
|
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
import { UserConfig } from "vite";
|
|
2
|
-
|
|
3
|
-
* Creates a Vite configuration for building dynamic modules
|
|
4
|
-
*/
|
|
1
|
+
import type { UserConfig } from "vite";
|
|
2
|
+
import type { DynamicModuleOptions } from "../types.js";
|
|
5
3
|
export default function dynamicModuleConfiguration(pkg: {
|
|
6
4
|
name: string;
|
|
7
5
|
version: string;
|
|
8
|
-
|
|
9
|
-
}, options: UserConfig & {
|
|
10
|
-
entry?: string;
|
|
11
|
-
outDir?: string;
|
|
12
|
-
moduleName?: string;
|
|
13
|
-
compatibility: {
|
|
14
|
-
framework: string;
|
|
15
|
-
modules?: Record<string, string>;
|
|
16
|
-
};
|
|
17
|
-
externals?: string[];
|
|
18
|
-
}): UserConfig;
|
|
6
|
+
}, options: DynamicModuleOptions): UserConfig;
|
|
19
7
|
//# sourceMappingURL=vite.dynamic-module.appconfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.dynamic-module.appconfig.d.ts","sourceRoot":"","sources":["../../src/templates/vite.dynamic-module.appconfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vite.dynamic-module.appconfig.d.ts","sourceRoot":"","sources":["../../src/templates/vite.dynamic-module.appconfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAU,UAAU,EAAE,MAAM,MAAM,CAAC;AAE/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAiD/D,MAAM,CAAC,OAAO,UAAU,0BAA0B,CAChD,GAAG,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EACtC,OAAO,EAAE,oBAAoB,GAC5B,UAAU,CAsBZ"}
|
|
@@ -1,176 +1,72 @@
|
|
|
1
|
-
import { defineConfig } from "vite";
|
|
2
|
-
import { resolve, join } from "node:path";
|
|
3
|
-
import { cwd } from "node:process";
|
|
4
|
-
import fs from "node:fs";
|
|
5
|
-
import { createHash } from "node:crypto";
|
|
6
1
|
import vue from "@vitejs/plugin-vue";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"vue-i18n",
|
|
13
|
-
"lodash-es",
|
|
14
|
-
"@vueuse/core",
|
|
15
|
-
/^@vc-shell\/framework(\/|$)/,
|
|
16
|
-
];
|
|
17
|
-
function sanitizeFileToken(value) {
|
|
18
|
-
const safeValue = value.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
19
|
-
return safeValue || "unknown";
|
|
20
|
-
}
|
|
2
|
+
import { federation } from "@module-federation/vite";
|
|
3
|
+
import { REMOTE_SHARED } from "./shared-deps.js";
|
|
4
|
+
import { cwd } from "node:process";
|
|
5
|
+
import { resolve } from "node:path";
|
|
6
|
+
import { realpathSync } from "node:fs";
|
|
21
7
|
/**
|
|
22
|
-
*
|
|
8
|
+
* Strips CSS/style from ALL files outside the module's own source directory.
|
|
9
|
+
* Remote MF modules should not emit CSS from shared deps (framework, vue, etc.)
|
|
10
|
+
* because the host app already provides all base styles, component CSS, and fonts.
|
|
11
|
+
*
|
|
12
|
+
* Works regardless of how deps are resolved (node_modules, portal:, link:, etc.)
|
|
23
13
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
manifest: "manifest.json",
|
|
39
|
-
copyPublicDir: false,
|
|
40
|
-
sourcemap: true,
|
|
41
|
-
minify: false,
|
|
42
|
-
lib: {
|
|
43
|
-
entry: resolve(cwd(), entry),
|
|
44
|
-
fileName: (_, name) => `${name}.js`,
|
|
45
|
-
formats: ["umd"],
|
|
46
|
-
name: uniqueModuleName,
|
|
47
|
-
},
|
|
48
|
-
outDir: join(cwd(), outDir),
|
|
49
|
-
rollupOptions: {
|
|
50
|
-
output: {
|
|
51
|
-
// Hash-based names prevent stale assets even when semantic version is unchanged.
|
|
52
|
-
entryFileNames: "[name]-[hash].js",
|
|
53
|
-
chunkFileNames: "[name]-[hash].js",
|
|
54
|
-
assetFileNames: "[name]-[hash].[ext]",
|
|
55
|
-
globals: {
|
|
56
|
-
vue: "Vue",
|
|
57
|
-
"vue-router": "VueRouter",
|
|
58
|
-
"vee-validate": "VeeValidate",
|
|
59
|
-
"vue-i18n": "VueI18n",
|
|
60
|
-
"lodash-es": "_",
|
|
61
|
-
"@vueuse/core": "VueUse",
|
|
62
|
-
"@vc-shell/framework": "VcShellFramework",
|
|
63
|
-
},
|
|
64
|
-
// Add version information to generated code
|
|
65
|
-
banner: () => {
|
|
66
|
-
const versionInfo = {
|
|
67
|
-
version,
|
|
68
|
-
compatibleWith: {
|
|
69
|
-
framework: compatibility.framework,
|
|
70
|
-
modules: compatibility.modules || {},
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
return `
|
|
74
|
-
/* Module Version Info */
|
|
75
|
-
(function() {
|
|
76
|
-
if (typeof window !== 'undefined') {
|
|
77
|
-
window.__VC_SHELL_MODULE_VERSION_INFO__ = window.__VC_SHELL_MODULE_VERSION_INFO__ || {};
|
|
78
|
-
window.__VC_SHELL_MODULE_VERSION_INFO__["${name}"] = ${JSON.stringify(versionInfo)};
|
|
79
|
-
}
|
|
80
|
-
})();
|
|
81
|
-
`;
|
|
82
|
-
},
|
|
83
|
-
// Add footer to properly register module in global scope
|
|
84
|
-
footer: () => {
|
|
85
|
-
return `
|
|
86
|
-
/* Module Registration */
|
|
87
|
-
(function() {
|
|
88
|
-
if (typeof window !== 'undefined' && typeof ${uniqueModuleName} !== 'undefined') {
|
|
89
|
-
// Ensure global object exists
|
|
90
|
-
if (!window.VcShellDynamicModules) {
|
|
91
|
-
window.VcShellDynamicModules = {};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Register module with unique name to avoid conflicts
|
|
95
|
-
window.VcShellDynamicModules["${name}"] = ${uniqueModuleName};
|
|
96
|
-
console.log('Registered module: ${name}');
|
|
97
|
-
|
|
98
|
-
// Dispatch custom event to notify that module is registered
|
|
99
|
-
if (typeof CustomEvent !== 'undefined') {
|
|
100
|
-
window.dispatchEvent(new CustomEvent('vc-shell-module-registered', {
|
|
101
|
-
detail: { moduleName: '${name}', moduleObject: ${uniqueModuleName} }
|
|
102
|
-
}));
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// For debugging: log the current state
|
|
106
|
-
console.log('Current VcShellDynamicModules:', Object.keys(window.VcShellDynamicModules));
|
|
107
|
-
}
|
|
108
|
-
})();
|
|
109
|
-
`;
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
external: allExternals,
|
|
113
|
-
},
|
|
14
|
+
function stripExternalStyles() {
|
|
15
|
+
let normalizedRoot;
|
|
16
|
+
return {
|
|
17
|
+
name: "strip-external-styles",
|
|
18
|
+
enforce: "pre",
|
|
19
|
+
buildStart() {
|
|
20
|
+
// Resolve symlinks once at build start, not at import time.
|
|
21
|
+
// This handles yarn link, portal:, and other symlink scenarios.
|
|
22
|
+
try {
|
|
23
|
+
normalizedRoot = realpathSync(resolve(cwd()));
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
normalizedRoot = resolve(cwd());
|
|
27
|
+
}
|
|
114
28
|
},
|
|
29
|
+
transform(code, id) {
|
|
30
|
+
// Normalize the incoming id as well to handle symlinked deps
|
|
31
|
+
let normalizedId;
|
|
32
|
+
try {
|
|
33
|
+
// Strip query params (e.g. ?type=style) before resolving
|
|
34
|
+
const idPath = id.split("?")[0];
|
|
35
|
+
normalizedId = realpathSync(idPath);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
normalizedId = id;
|
|
39
|
+
}
|
|
40
|
+
if (/type=style/.test(id) && !normalizedId.startsWith(normalizedRoot)) {
|
|
41
|
+
return { code: "", map: null };
|
|
42
|
+
}
|
|
43
|
+
if (/\.(css|scss|sass|less|styl)$/.test(id) && !normalizedId.startsWith(normalizedRoot)) {
|
|
44
|
+
return { code: "", map: null };
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export default function dynamicModuleConfiguration(pkg, options) {
|
|
51
|
+
const entry = options.entry ?? "./src/modules/index.ts";
|
|
52
|
+
return {
|
|
115
53
|
plugins: [
|
|
54
|
+
stripExternalStyles(),
|
|
116
55
|
vue(),
|
|
117
|
-
{
|
|
118
|
-
name:
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
closeBundle: async () => {
|
|
123
|
-
const manifestPath = join(cwd(), outDir, "manifest.json");
|
|
124
|
-
if (fs.existsSync(manifestPath)) {
|
|
125
|
-
try {
|
|
126
|
-
// Read generated manifest
|
|
127
|
-
const manifestContent = await fs.promises.readFile(manifestPath, "utf-8");
|
|
128
|
-
const manifest = JSON.parse(manifestContent);
|
|
129
|
-
const manifestHash = sanitizeFileToken(createHash("sha256").update(manifestContent).digest("hex").slice(0, 12));
|
|
130
|
-
const hashedManifestFileName = `manifest.${manifestHash}.json`;
|
|
131
|
-
const hashedManifestPath = join(cwd(), outDir, hashedManifestFileName);
|
|
132
|
-
// Add file with metadata about version
|
|
133
|
-
const versionFileName = `version.${manifestHash}.json`;
|
|
134
|
-
const versionFilePath = join(cwd(), outDir, versionFileName);
|
|
135
|
-
// Create information about version
|
|
136
|
-
const versionInfo = {
|
|
137
|
-
version,
|
|
138
|
-
compatibleWith: {
|
|
139
|
-
framework: compatibility.framework,
|
|
140
|
-
modules: compatibility.modules || {},
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
// Write file with version
|
|
144
|
-
await fs.promises.writeFile(versionFilePath, JSON.stringify(versionInfo, null, 2));
|
|
145
|
-
// Remove stale version metadata records from previous builds.
|
|
146
|
-
for (const key of Object.keys(manifest)) {
|
|
147
|
-
if (manifest[key]?.isVersionInfo) {
|
|
148
|
-
delete manifest[key];
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
// Add information about version file to manifest
|
|
152
|
-
manifest[versionFileName] = {
|
|
153
|
-
file: versionFileName,
|
|
154
|
-
src: versionFileName,
|
|
155
|
-
isVersionInfo: true, // Add special marker
|
|
156
|
-
};
|
|
157
|
-
const serializedManifest = JSON.stringify(manifest, null, 2);
|
|
158
|
-
// Write updated default manifest for backward compatibility
|
|
159
|
-
await fs.promises.writeFile(manifestPath, serializedManifest);
|
|
160
|
-
// Write hash-based manifest for deployments that expose build hash in apps.json.
|
|
161
|
-
await fs.promises.writeFile(hashedManifestPath, serializedManifest);
|
|
162
|
-
console.log(`✓ Version information added to manifests: ${manifestPath}, ${hashedManifestFileName}`);
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
console.error("Error updating manifest with version info:", error);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
console.warn(`Manifest file not found at ${manifestPath}`);
|
|
170
|
-
}
|
|
56
|
+
federation({
|
|
57
|
+
name: pkg.name,
|
|
58
|
+
filename: "remoteEntry.js",
|
|
59
|
+
exposes: options.exposes ?? {
|
|
60
|
+
"./module": entry,
|
|
171
61
|
},
|
|
172
|
-
|
|
62
|
+
shared: { ...REMOTE_SHARED },
|
|
63
|
+
dts: false,
|
|
64
|
+
}),
|
|
173
65
|
],
|
|
174
|
-
|
|
66
|
+
build: {
|
|
67
|
+
target: "esnext",
|
|
68
|
+
outDir: "dist",
|
|
69
|
+
},
|
|
70
|
+
};
|
|
175
71
|
}
|
|
176
72
|
//# sourceMappingURL=vite.dynamic-module.appconfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.dynamic-module.appconfig.js","sourceRoot":"","sources":["../../src/templates/vite.dynamic-module.appconfig.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"vite.dynamic-module.appconfig.js","sourceRoot":"","sources":["../../src/templates/vite.dynamic-module.appconfig.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,oBAAoB,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC;;;;;;GAMG;AACH,SAAS,mBAAmB;IAC1B,IAAI,cAAsB,CAAC;IAE3B,OAAO;QACL,IAAI,EAAE,uBAAuB;QAC7B,OAAO,EAAE,KAAK;QACd,UAAU;YACR,4DAA4D;YAC5D,gEAAgE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gBAC1B,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI;oBAC1B,UAAU,EAAE,KAAK;iBAClB;gBACD,MAAM,EAAE,EAAE,GAAG,aAAa,EAAE;gBAC5B,GAAG,EAAE,KAAK;aACX,CAAC;SACH;QACD,KAAK,EAAE;YACL,MAAM,EAAE,QAAQ;YAChB,MAAM,EAAE,MAAM;SACf;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.dynamic-module.appconfig.test.d.ts","sourceRoot":"","sources":["../../src/templates/vite.dynamic-module.appconfig.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
vi.mock("@module-federation/vite", () => ({
|
|
3
|
+
federation: vi.fn((config) => ({ name: "mf-plugin", _config: config })),
|
|
4
|
+
}));
|
|
5
|
+
vi.mock("@vitejs/plugin-vue", () => ({
|
|
6
|
+
default: vi.fn(() => ({ name: "vue-plugin" })),
|
|
7
|
+
}));
|
|
8
|
+
import dynamicModuleConfiguration from "./vite.dynamic-module.appconfig.js";
|
|
9
|
+
describe("dynamicModuleConfiguration (MF)", () => {
|
|
10
|
+
const pkg = { name: "reviews", version: "1.0.0" };
|
|
11
|
+
it("produces MF remote config with correct name and exposes", () => {
|
|
12
|
+
const config = dynamicModuleConfiguration(pkg, {
|
|
13
|
+
compatibility: { framework: "^2.0.0" },
|
|
14
|
+
});
|
|
15
|
+
expect(config.plugins).toBeDefined();
|
|
16
|
+
const mfPlugin = config.plugins.find((p) => p._config);
|
|
17
|
+
expect(mfPlugin._config.name).toBe("reviews");
|
|
18
|
+
expect(mfPlugin._config.filename).toBe("remoteEntry.js");
|
|
19
|
+
expect(mfPlugin._config.exposes["./module"]).toBe("./src/modules/index.ts");
|
|
20
|
+
});
|
|
21
|
+
it("uses custom entry point when provided", () => {
|
|
22
|
+
const config = dynamicModuleConfiguration(pkg, {
|
|
23
|
+
entry: "./src/custom.ts",
|
|
24
|
+
compatibility: { framework: "^2.0.0" },
|
|
25
|
+
});
|
|
26
|
+
const mfPlugin = config.plugins.find((p) => p._config);
|
|
27
|
+
expect(mfPlugin._config.exposes["./module"]).toBe("./src/custom.ts");
|
|
28
|
+
});
|
|
29
|
+
it("sets build target to esnext", () => {
|
|
30
|
+
const config = dynamicModuleConfiguration(pkg, {
|
|
31
|
+
compatibility: { framework: "^2.0.0" },
|
|
32
|
+
});
|
|
33
|
+
expect(config.build?.target).toBe("esnext");
|
|
34
|
+
});
|
|
35
|
+
it("includes shared deps with singleton: true", () => {
|
|
36
|
+
const config = dynamicModuleConfiguration(pkg, {
|
|
37
|
+
compatibility: { framework: "^2.0.0" },
|
|
38
|
+
});
|
|
39
|
+
const mfPlugin = config.plugins.find((p) => p._config);
|
|
40
|
+
expect(mfPlugin._config.shared.vue.singleton).toBe(true);
|
|
41
|
+
expect(mfPlugin._config.shared["@vc-shell/framework"].singleton).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
it("stripExternalStyles plugin has buildStart hook for path normalization", () => {
|
|
44
|
+
const config = dynamicModuleConfiguration({ name: "test-module", version: "1.0.0" }, {});
|
|
45
|
+
const stripPlugin = config.plugins?.flat().find((p) => p?.name === "strip-external-styles");
|
|
46
|
+
expect(stripPlugin).toBeDefined();
|
|
47
|
+
expect(typeof stripPlugin.buildStart).toBe("function");
|
|
48
|
+
expect(typeof stripPlugin.transform).toBe("function");
|
|
49
|
+
});
|
|
50
|
+
it("uses custom exposes when provided", () => {
|
|
51
|
+
const config = dynamicModuleConfiguration(pkg, {
|
|
52
|
+
exposes: { "./custom": "./src/custom.ts" },
|
|
53
|
+
compatibility: { framework: "^2.0.0" },
|
|
54
|
+
});
|
|
55
|
+
const mfPlugin = config.plugins.find((p) => p._config);
|
|
56
|
+
expect(mfPlugin._config.exposes["./custom"]).toBe("./src/custom.ts");
|
|
57
|
+
expect(mfPlugin._config.exposes["./module"]).toBeUndefined();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=vite.dynamic-module.appconfig.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.dynamic-module.appconfig.test.js","sourceRoot":"","sources":["../../src/templates/vite.dynamic-module.appconfig.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAElD,EAAE,CAAC,IAAI,CAAC,yBAAyB,EAAE,GAAG,EAAE,CAAC,CAAC;IACxC,UAAU,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,MAAW,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;CAC7E,CAAC,CAAC,CAAC;AAEJ,EAAE,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,CAAC;IACnC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;CAC/C,CAAC,CAAC,CAAC;AAEJ,OAAO,0BAA0B,MAAM,iCAAiC,CAAC;AAEzE,QAAQ,CAAC,iCAAiC,EAAE,GAAG,EAAE;IAC/C,MAAM,GAAG,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IAElD,EAAE,CAAC,yDAAyD,EAAE,GAAG,EAAE;QACjE,MAAM,MAAM,GAAG,0BAA0B,CAAC,GAAG,EAAE;YAC7C,aAAa,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE;SACvC,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAI,MAAM,CAAC,OAAiB,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,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IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACvE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACrE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;IAC/D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { UserConfig } from "vite";
|
|
2
|
+
import { type SharedDepConfig } from "./shared-deps.js";
|
|
3
|
+
export interface HostFederationOptions {
|
|
4
|
+
sharedDeps?: Record<string, SharedDepConfig>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Vite plugin configuration for Module Federation HOST apps.
|
|
8
|
+
*
|
|
9
|
+
* **Build-time only.** This configures the MF build plugin so Vite can:
|
|
10
|
+
* - Resolve `import` statements to shared deps without bundling duplicates
|
|
11
|
+
* - Generate proper chunk structure for MF host semantics
|
|
12
|
+
*
|
|
13
|
+
* **Does NOT replace runtime init().** The runtime loader (`loader-mf.ts`)
|
|
14
|
+
* still calls `@module-federation/enhanced/runtime` `init()` to register
|
|
15
|
+
* actual module instances (`lib: () => Vue`, etc.) and discover remotes
|
|
16
|
+
* from the server registry. Build-time plugin handles bundling;
|
|
17
|
+
* runtime init handles module provision.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* // vite.config.ts (host app)
|
|
22
|
+
* import { getApplicationConfiguration, getHostFederationConfig } from "@vc-shell/config-generator";
|
|
23
|
+
* import { mergeConfig } from "vite";
|
|
24
|
+
*
|
|
25
|
+
* export default mergeConfig(
|
|
26
|
+
* getApplicationConfiguration(),
|
|
27
|
+
* getHostFederationConfig(),
|
|
28
|
+
* );
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function getHostFederationConfig(options?: HostFederationOptions): UserConfig;
|
|
32
|
+
//# sourceMappingURL=vite.host.appconfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.host.appconfig.d.ts","sourceRoot":"","sources":["../../src/templates/vite.host.appconfig.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAErE,MAAM,WAAW,qBAAqB;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,CAAC,EAAE,qBAAqB,GAC9B,UAAU,CAaZ"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { federation } from "@module-federation/vite";
|
|
2
|
+
import { DEFAULT_SHARED } from "./shared-deps.js";
|
|
3
|
+
/**
|
|
4
|
+
* Vite plugin configuration for Module Federation HOST apps.
|
|
5
|
+
*
|
|
6
|
+
* **Build-time only.** This configures the MF build plugin so Vite can:
|
|
7
|
+
* - Resolve `import` statements to shared deps without bundling duplicates
|
|
8
|
+
* - Generate proper chunk structure for MF host semantics
|
|
9
|
+
*
|
|
10
|
+
* **Does NOT replace runtime init().** The runtime loader (`loader-mf.ts`)
|
|
11
|
+
* still calls `@module-federation/enhanced/runtime` `init()` to register
|
|
12
|
+
* actual module instances (`lib: () => Vue`, etc.) and discover remotes
|
|
13
|
+
* from the server registry. Build-time plugin handles bundling;
|
|
14
|
+
* runtime init handles module provision.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* // vite.config.ts (host app)
|
|
19
|
+
* import { getApplicationConfiguration, getHostFederationConfig } from "@vc-shell/config-generator";
|
|
20
|
+
* import { mergeConfig } from "vite";
|
|
21
|
+
*
|
|
22
|
+
* export default mergeConfig(
|
|
23
|
+
* getApplicationConfiguration(),
|
|
24
|
+
* getHostFederationConfig(),
|
|
25
|
+
* );
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function getHostFederationConfig(options) {
|
|
29
|
+
return {
|
|
30
|
+
plugins: [
|
|
31
|
+
federation({
|
|
32
|
+
name: "host",
|
|
33
|
+
remotes: {},
|
|
34
|
+
shared: {
|
|
35
|
+
...DEFAULT_SHARED,
|
|
36
|
+
...options?.sharedDeps,
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=vite.host.appconfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.host.appconfig.js","sourceRoot":"","sources":["../../src/templates/vite.host.appconfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAwB,MAAM,eAAe,CAAC;AAMrE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAA+B;IAE/B,OAAO;QACL,OAAO,EAAE;YACP,UAAU,CAAC;gBACT,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,EAAE;gBACX,MAAM,EAAE;oBACN,GAAG,cAAc;oBACjB,GAAG,OAAO,EAAE,UAAU;iBACvB;aACF,CAAC;SACH;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.host.appconfig.test.d.ts","sourceRoot":"","sources":["../../src/templates/vite.host.appconfig.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { SHARED_DEP_NAMES } from "./shared-deps.js";
|
|
3
|
+
vi.mock("@module-federation/vite", () => ({
|
|
4
|
+
federation: vi.fn((config) => ({ name: "mf-plugin", _config: config })),
|
|
5
|
+
}));
|
|
6
|
+
import { getHostFederationConfig } from "./vite.host.appconfig.js";
|
|
7
|
+
it("SHARED_DEP_NAMES matches SHARED_DEPS_BASE keys", () => {
|
|
8
|
+
expect(SHARED_DEP_NAMES).toEqual(expect.arrayContaining([
|
|
9
|
+
"vue", "vue-router", "vue-i18n", "vee-validate",
|
|
10
|
+
"lodash-es", "@vueuse/core", "@vc-shell/framework",
|
|
11
|
+
]));
|
|
12
|
+
expect(SHARED_DEP_NAMES.length).toBe(7);
|
|
13
|
+
});
|
|
14
|
+
describe("getHostFederationConfig", () => {
|
|
15
|
+
it("returns config with MF plugin containing default shared deps", () => {
|
|
16
|
+
const config = getHostFederationConfig();
|
|
17
|
+
expect(config.plugins).toBeDefined();
|
|
18
|
+
expect(config.plugins).toHaveLength(1);
|
|
19
|
+
const plugin = config.plugins[0];
|
|
20
|
+
expect(plugin.name).toBe("mf-plugin");
|
|
21
|
+
const mfConfig = plugin._config;
|
|
22
|
+
expect(mfConfig.name).toBe("host");
|
|
23
|
+
expect(mfConfig.remotes).toEqual({});
|
|
24
|
+
const shared = mfConfig.shared;
|
|
25
|
+
expect(shared.vue).toEqual({ singleton: true, requiredVersion: "^3.4.0" });
|
|
26
|
+
expect(shared["vue-router"]).toEqual({ singleton: true, requiredVersion: "^4.0.0" });
|
|
27
|
+
expect(shared["vue-i18n"]).toEqual({ singleton: true, requiredVersion: "^9.0.0" });
|
|
28
|
+
expect(shared["@vc-shell/framework"]).toEqual({ singleton: true });
|
|
29
|
+
expect(shared["vee-validate"]).toEqual({ singleton: true });
|
|
30
|
+
expect(shared["lodash-es"]).toEqual({ singleton: true });
|
|
31
|
+
expect(shared["@vueuse/core"]).toEqual({ singleton: true });
|
|
32
|
+
});
|
|
33
|
+
it("merges custom sharedDeps while keeping defaults", () => {
|
|
34
|
+
const config = getHostFederationConfig({
|
|
35
|
+
sharedDeps: {
|
|
36
|
+
"my-lib": { singleton: true, requiredVersion: "^2.0.0" },
|
|
37
|
+
vue: { singleton: true, requiredVersion: "^3.5.0", eager: true },
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
const plugin = config.plugins[0];
|
|
41
|
+
const shared = plugin._config.shared;
|
|
42
|
+
// Custom dep added
|
|
43
|
+
expect(shared["my-lib"]).toEqual({ singleton: true, requiredVersion: "^2.0.0" });
|
|
44
|
+
// Vue overridden by custom
|
|
45
|
+
expect(shared.vue).toEqual({ singleton: true, requiredVersion: "^3.5.0", eager: true });
|
|
46
|
+
// Other defaults preserved
|
|
47
|
+
expect(shared["vue-router"]).toEqual({ singleton: true, requiredVersion: "^4.0.0" });
|
|
48
|
+
expect(shared["@vc-shell/framework"]).toEqual({ singleton: true });
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=vite.host.appconfig.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.host.appconfig.test.js","sourceRoot":"","sources":["../../src/templates/vite.host.appconfig.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,EAAE,CAAC,IAAI,CAAC,yBAAyB,EAAE,GAAG,EAAE,CAAC,CAAC;IACxC,UAAU,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,MAAe,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;CACjF,CAAC,CAAC,CAAC;AAEJ,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;IACxD,MAAM,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAC9B,MAAM,CAAC,eAAe,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,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAExF,2BAA2B;QAC3B,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,CAAC;QACrF,MAAM,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -15,33 +15,22 @@ export interface CompatibilityOptions {
|
|
|
15
15
|
modules?: Record<string, string>;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
* Dynamic module configuration options
|
|
18
|
+
* Dynamic module configuration options (Module Federation)
|
|
19
19
|
*/
|
|
20
20
|
export interface DynamicModuleOptions extends UserConfig {
|
|
21
21
|
/**
|
|
22
22
|
* Entry point for the module
|
|
23
|
-
* @default "./index.ts"
|
|
23
|
+
* @default "./src/modules/index.ts"
|
|
24
24
|
*/
|
|
25
25
|
entry?: string;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
28
|
-
* @default "dist/packages/modules"
|
|
27
|
+
* Custom MF exposes map. Overrides default `{ "./module": entry }`.
|
|
29
28
|
*/
|
|
30
|
-
|
|
29
|
+
exposes?: Record<string, string>;
|
|
31
30
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* Compatibility constraints (metadata only — not used during build).
|
|
32
|
+
* Used by the runtime registry API for version filtering.
|
|
34
33
|
*/
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Compatibility constraints for the module
|
|
38
|
-
* @required Both framework and apps fields are required
|
|
39
|
-
*/
|
|
40
|
-
compatibility: CompatibilityOptions;
|
|
41
|
-
/**
|
|
42
|
-
* Additional external dependencies
|
|
43
|
-
* @default []
|
|
44
|
-
*/
|
|
45
|
-
externals?: string[];
|
|
34
|
+
compatibility?: CompatibilityOptions;
|
|
46
35
|
}
|
|
47
36
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,UAAU;IACtD;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,UAAU;IACtD;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC;;;OAGG;IACH,aAAa,CAAC,EAAE,oBAAoB,CAAC;CACtC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vc-shell/config-generator",
|
|
3
3
|
"description": "Generate Vite configurations",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0-alpha.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"build": "tsc && tsc-alias"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
+
"@module-federation/vite": "^1.12.0",
|
|
15
16
|
"@vitejs/plugin-vue": "^5.2.3",
|
|
16
17
|
"vite": "^6.3.3",
|
|
17
18
|
"vite-plugin-checker": "^0.9.1",
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
"vue": "^3.5.13"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
|
-
"@vc-shell/ts-config": "
|
|
24
|
+
"@vc-shell/ts-config": "2.0.0-alpha.0",
|
|
24
25
|
"http-proxy-middleware": "^3.0.2",
|
|
25
26
|
"rollup-plugin-visualizer": "^6.0.3",
|
|
26
27
|
"tsc-alias": "^1.8.8",
|
|
@@ -30,5 +31,5 @@
|
|
|
30
31
|
"access": "public",
|
|
31
32
|
"registry": "https://registry.npmjs.org/"
|
|
32
33
|
},
|
|
33
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "f028d9e1fe410a18fec4e127a65860cfb2309e36"
|
|
34
35
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Function to determine if a module should be treated as external
|
|
3
|
-
* @param {string} id - The module ID
|
|
4
|
-
* @returns {boolean} - True if the module is external, false otherwise
|
|
5
|
-
*/
|
|
6
|
-
export declare const external: (id: string) => boolean;
|
|
7
|
-
//# sourceMappingURL=external.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../../src/templates/external.ts"],"names":[],"mappings":"AAeA;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,IAAI,MAAM,KAAG,OAMrC,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { cwd } from "node:process";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
const packageJson = JSON.parse(fs.readFileSync(path.join(cwd(), "package.json"), "utf-8"));
|
|
5
|
-
const externalPackages = [
|
|
6
|
-
...Object.keys(packageJson.dependencies || {}),
|
|
7
|
-
...Object.keys(packageJson.peerDependencies || {}),
|
|
8
|
-
...Object.keys(packageJson.devDependencies || {}),
|
|
9
|
-
];
|
|
10
|
-
// Create a regex to match external packages
|
|
11
|
-
const externalRegex = new RegExp(`^(${externalPackages.join("|").replace(/\//g, "\\/")})($|\\/)`);
|
|
12
|
-
/**
|
|
13
|
-
* Function to determine if a module should be treated as external
|
|
14
|
-
* @param {string} id - The module ID
|
|
15
|
-
* @returns {boolean} - True if the module is external, false otherwise
|
|
16
|
-
*/
|
|
17
|
-
export const external = (id) => {
|
|
18
|
-
const isExternal = externalRegex.test(id);
|
|
19
|
-
if (id.includes("lodash")) {
|
|
20
|
-
console.log(`[EXTERNAL_CHECK] id: '${id}', isExternal: ${isExternal}`);
|
|
21
|
-
}
|
|
22
|
-
return isExternal;
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=external.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"external.js","sourceRoot":"","sources":["../../src/templates/external.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;AAE3F,MAAM,gBAAgB,GAAG;IACvB,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,IAAI,EAAE,CAAC;IAC9C,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,IAAI,EAAE,CAAC;IAClD,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,eAAe,IAAI,EAAE,CAAC;CAClD,CAAC;AAEF,4CAA4C;AAC5C,MAAM,aAAa,GAAG,IAAI,MAAM,CAAC,KAAK,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;AAElG;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAU,EAAW,EAAE;IAC9C,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1C,IAAI,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,kBAAkB,UAAU,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC"}
|