@shellui/cli 0.0.18 → 0.0.19
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/package.json +2 -2
- package/src/commands/build.js +4 -9
- package/src/commands/start.js +8 -10
- package/src/utils/index.js +2 -0
- package/src/utils/service-worker-plugin.js +0 -5
- package/src/utils/vite.js +28 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shellui/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "ShellUI CLI - Command-line tool for ShellUI",
|
|
5
5
|
"main": "src/cli.js",
|
|
6
6
|
"type": "module",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"tsx": "^4.21.0",
|
|
31
31
|
"vite": "7.3.1",
|
|
32
32
|
"workbox-build": "^7.1.0",
|
|
33
|
-
"@shellui/core": "0.0.
|
|
33
|
+
"@shellui/core": "0.0.19"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
package/src/commands/build.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
createResolveAlias,
|
|
11
11
|
createPostCSSConfig,
|
|
12
12
|
createViteDefine,
|
|
13
|
+
createViteResolveConfig,
|
|
13
14
|
resolvePackagePath,
|
|
14
15
|
} from '../utils/index.js';
|
|
15
16
|
|
|
@@ -76,6 +77,7 @@ export async function buildCommand(root = '.') {
|
|
|
76
77
|
// Get core package paths
|
|
77
78
|
const corePackagePath = resolvePackagePath('@shellui/core');
|
|
78
79
|
const coreSrcPath = getCoreSrcPath();
|
|
80
|
+
const resolveConfig = createViteResolveConfig();
|
|
79
81
|
const resolveAlias = createResolveAlias();
|
|
80
82
|
const postcssConfig = createPostCSSConfig();
|
|
81
83
|
|
|
@@ -86,14 +88,8 @@ export async function buildCommand(root = '.') {
|
|
|
86
88
|
plugins: [react()],
|
|
87
89
|
define: createViteDefine(config),
|
|
88
90
|
resolve: {
|
|
91
|
+
...resolveConfig,
|
|
89
92
|
alias: resolveAlias,
|
|
90
|
-
// Dedupe React and core package to prevent duplicate module instances
|
|
91
|
-
// This is critical for React Context to work correctly in micro-frontends
|
|
92
|
-
dedupe: ['react', 'react-dom', '@shellui/core'],
|
|
93
|
-
// Ensure consistent module resolution to prevent duplicate instances
|
|
94
|
-
// when the same module is imported via different paths (relative, alias, with/without extensions)
|
|
95
|
-
conditions: ['import', 'module', 'browser', 'default'],
|
|
96
|
-
preserveSymlinks: false,
|
|
97
93
|
},
|
|
98
94
|
css: {
|
|
99
95
|
postcss: postcssConfig,
|
|
@@ -131,9 +127,8 @@ export async function buildCommand(root = '.') {
|
|
|
131
127
|
root: coreSrcPath,
|
|
132
128
|
define: createViteDefine(config),
|
|
133
129
|
resolve: {
|
|
130
|
+
...resolveConfig,
|
|
134
131
|
alias: resolveAlias,
|
|
135
|
-
// Dedupe React and core package to prevent duplicate module instances
|
|
136
|
-
dedupe: ['react', 'react-dom', '@shellui/core'],
|
|
137
132
|
},
|
|
138
133
|
build: {
|
|
139
134
|
outDir: distPath,
|
package/src/commands/start.js
CHANGED
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
createResolveAlias,
|
|
10
10
|
createPostCSSConfig,
|
|
11
11
|
createViteDefine,
|
|
12
|
+
createViteResolveConfig,
|
|
13
|
+
createViteOptimizeDepsConfig,
|
|
12
14
|
resolvePackagePath,
|
|
13
15
|
} from '../utils/index.js';
|
|
14
16
|
import { serviceWorkerDevPlugin } from '../utils/service-worker-plugin.js';
|
|
@@ -37,22 +39,18 @@ async function startServer(root, cwd, shouldOpen = false) {
|
|
|
37
39
|
const staticPath = path.resolve(cwd, root, 'static');
|
|
38
40
|
const publicDir = fs.existsSync(staticPath) ? staticPath : false;
|
|
39
41
|
|
|
42
|
+
const resolveConfig = createViteResolveConfig();
|
|
43
|
+
const resolveAlias = createResolveAlias();
|
|
44
|
+
|
|
40
45
|
const server = await createServer({
|
|
41
46
|
root: coreSrcPath,
|
|
42
47
|
plugins: [react(), serviceWorkerDevPlugin(corePackagePath, coreSrcPath)],
|
|
43
48
|
define: createViteDefine(config),
|
|
44
49
|
resolve: {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// This is critical for React Context to work correctly in micro-frontends
|
|
48
|
-
// When React is a peer dependency, dedupe ensures Vite uses a single instance
|
|
49
|
-
dedupe: ['react', 'react-dom', '@shellui/core'],
|
|
50
|
-
// Ensure consistent module resolution to prevent duplicate instances
|
|
51
|
-
// when the same module is imported via different paths (relative, alias, with/without extensions)
|
|
52
|
-
conditions: ['import', 'module', 'browser', 'default'],
|
|
53
|
-
// Don't preserve symlinks - ensures consistent resolution in monorepos
|
|
54
|
-
preserveSymlinks: false,
|
|
50
|
+
...resolveConfig,
|
|
51
|
+
alias: resolveAlias,
|
|
55
52
|
},
|
|
53
|
+
optimizeDeps: createViteOptimizeDepsConfig(),
|
|
56
54
|
css: {
|
|
57
55
|
postcss: createPostCSSConfig(),
|
|
58
56
|
},
|
package/src/utils/index.js
CHANGED
|
@@ -35,11 +35,6 @@ export function serviceWorkerDevPlugin(corePackagePath, coreSrcPath) {
|
|
|
35
35
|
plugins: [react()],
|
|
36
36
|
resolve: {
|
|
37
37
|
alias: createResolveAlias(),
|
|
38
|
-
// Dedupe React and core package to prevent duplicate module instances
|
|
39
|
-
dedupe: ['react', 'react-dom', '@shellui/core'],
|
|
40
|
-
// Ensure consistent module resolution to prevent duplicate instances
|
|
41
|
-
conditions: ['import', 'module', 'browser', 'default'],
|
|
42
|
-
preserveSymlinks: false,
|
|
43
38
|
},
|
|
44
39
|
build: {
|
|
45
40
|
write: false,
|
package/src/utils/vite.js
CHANGED
|
@@ -38,19 +38,14 @@ export function getCoreSrcPath() {
|
|
|
38
38
|
* Always sets '@' to core/src. Sets '@shellui/sdk' to source entry when in
|
|
39
39
|
* workspace mode; omits the alias when installed from npm so Vite resolves
|
|
40
40
|
* through the package's exports field (dist/index.js).
|
|
41
|
-
*
|
|
42
|
-
* Also adds specific aliases for config module to ensure all imports
|
|
43
|
-
* (relative, alias, or with extensions) resolve to the same module instance.
|
|
44
|
-
* This prevents React Context duplication issues.
|
|
45
41
|
* @returns {Object} Vite resolve.alias object
|
|
46
42
|
*/
|
|
47
43
|
export function createResolveAlias() {
|
|
48
44
|
const corePackagePath = resolvePackagePath('@shellui/core');
|
|
49
|
-
const coreSrcPath = path.join(corePackagePath, 'src');
|
|
50
45
|
const sdkEntry = resolveSdkEntry();
|
|
51
46
|
|
|
52
47
|
const alias = {
|
|
53
|
-
'@':
|
|
48
|
+
'@': path.join(corePackagePath, 'src'),
|
|
54
49
|
};
|
|
55
50
|
|
|
56
51
|
if (sdkEntry) {
|
|
@@ -106,3 +101,30 @@ export function createViteDefine(config) {
|
|
|
106
101
|
__SHELLUI_SENTRY_RELEASE__: sentry?.release ? JSON.stringify(sentry.release) : 'undefined',
|
|
107
102
|
};
|
|
108
103
|
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Create Vite resolve configuration with deduplication.
|
|
107
|
+
* Prevents duplicate React instances and @shellui/core modules when running
|
|
108
|
+
* from node_modules, which can cause context provider issues in microfrontends.
|
|
109
|
+
* @returns {Object} Vite resolve configuration with dedupe
|
|
110
|
+
*/
|
|
111
|
+
export function createViteResolveConfig() {
|
|
112
|
+
return {
|
|
113
|
+
dedupe: ['react', 'react-dom', '@shellui/core'],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Create Vite optimizeDeps configuration to exclude @shellui/core from pre-bundling.
|
|
119
|
+
* This prevents Vite from creating duplicate module instances during dependency optimization,
|
|
120
|
+
* which is critical for React Context to work correctly in microfrontend iframe scenarios.
|
|
121
|
+
*
|
|
122
|
+
* Note: We do NOT exclude React/ReactDOM here because Vite needs to optimize them.
|
|
123
|
+
* The resolve.dedupe configuration handles ensuring only one React instance is used.
|
|
124
|
+
* @returns {Object} Vite optimizeDeps configuration
|
|
125
|
+
*/
|
|
126
|
+
export function createViteOptimizeDepsConfig() {
|
|
127
|
+
return {
|
|
128
|
+
exclude: ['@shellui/core'],
|
|
129
|
+
};
|
|
130
|
+
}
|