@file-viewer/vite-plugin 2.1.22 → 2.1.24
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.en.md +3 -0
- package/README.md +3 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +59 -0
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -91,8 +91,11 @@ const options = {
|
|
|
91
91
|
| `scan` | `true` or `{ roots, extensions, maxFileSize }`; scans source hints and merges formats |
|
|
92
92
|
| `inject` | Defaults to `true`; set `false` to import `virtual:file-viewer-renderers` manually |
|
|
93
93
|
| `chunkStrategy` | `'renderer' | 'none'`; controls renderer-level chunk grouping |
|
|
94
|
+
| `stabilizeInteropChunks` | Defaults to `true`; when the host project already defines a `manualChunks` function, keeps CodeMirror / Lezer / Sandpack in one chunk to avoid production TDZ initialization errors |
|
|
94
95
|
| `missingRenderer` | `'error' | 'warn' | 'ignore'`; controls notices for planned renderer mappings |
|
|
95
96
|
|
|
97
|
+
When host apps split `node_modules` by package name, circular dependencies between `@codemirror/*`, `@lezer/*`, and Sandpack can show up in production as `codemirror-view.* Cannot access ... before initialization`. The plugin wraps existing `manualChunks` functions by default, stabilizes only those known interop chunks, and preserves the rest of the app's custom grouping. Set `stabilizeInteropChunks:false` only when the host build needs total control.
|
|
98
|
+
|
|
96
99
|
For strict registry control, disable injection and pass the virtual module explicitly:
|
|
97
100
|
|
|
98
101
|
```ts
|
package/README.md
CHANGED
|
@@ -91,8 +91,11 @@ const options = {
|
|
|
91
91
|
| `scan` | `true` 或 `{ roots, extensions, maxFileSize }`,扫描源码 hint 并合并格式 |
|
|
92
92
|
| `inject` | 默认 `true`;设为 `false` 后手动导入 `virtual:file-viewer-renderers` |
|
|
93
93
|
| `chunkStrategy` | `'renderer' | 'none'`,控制是否注入 renderer 级 chunk 分组 |
|
|
94
|
+
| `stabilizeInteropChunks` | 默认 `true`;当宿主项目已有 `manualChunks` 函数时,把 CodeMirror / Lezer / Sandpack 归到同一 chunk,避免生产构建 TDZ 初始化错误 |
|
|
94
95
|
| `missingRenderer` | `'error' | 'warn' | 'ignore'`,控制尚未提取的 renderer 映射提示方式 |
|
|
95
96
|
|
|
97
|
+
如果宿主项目按包名拆分 `node_modules`,`@codemirror/*`、`@lezer/*` 和 Sandpack 之间的循环依赖可能在生产构建中表现为 `codemirror-view.* Cannot access ... before initialization`。插件默认会包裹已有的 `manualChunks` 函数,只稳定这些已知互操作 chunk,保留其它自定义分组;确实需要完全接管时可设置 `stabilizeInteropChunks:false`。
|
|
98
|
+
|
|
96
99
|
如果你需要严格控制 registry,可以关闭注入并手动传入:
|
|
97
100
|
|
|
98
101
|
```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -75,6 +75,12 @@ export interface FileViewerRenderersPluginOptions {
|
|
|
75
75
|
* Adds renderer-oriented manualChunks when the user did not define one.
|
|
76
76
|
*/
|
|
77
77
|
chunkStrategy?: FileViewerChunkStrategy;
|
|
78
|
+
/**
|
|
79
|
+
* Wraps existing manualChunks functions with known circular-dependency-safe
|
|
80
|
+
* vendor groups. This keeps CodeMirror/Lezer/Sandpack in one chunk when host
|
|
81
|
+
* apps split node_modules by package name, avoiding production TDZ errors.
|
|
82
|
+
*/
|
|
83
|
+
stabilizeInteropChunks?: boolean;
|
|
78
84
|
/**
|
|
79
85
|
* Copies known worker/WASM/vendor assets for selected renderer lines.
|
|
80
86
|
*/
|
package/dist/index.js
CHANGED
|
@@ -691,6 +691,52 @@ function hasManualChunks(config) {
|
|
|
691
691
|
}
|
|
692
692
|
return Boolean(output?.manualChunks);
|
|
693
693
|
}
|
|
694
|
+
function getManualChunksFunction(config) {
|
|
695
|
+
const output = config.build?.rollupOptions?.output;
|
|
696
|
+
if (Array.isArray(output)) {
|
|
697
|
+
return null;
|
|
698
|
+
}
|
|
699
|
+
return typeof output?.manualChunks === 'function'
|
|
700
|
+
? output.manualChunks
|
|
701
|
+
: null;
|
|
702
|
+
}
|
|
703
|
+
function getNodeModulePackageName(id) {
|
|
704
|
+
const normalized = id.replace(/\\/g, '/');
|
|
705
|
+
const marker = '/node_modules/';
|
|
706
|
+
const index = normalized.lastIndexOf(marker);
|
|
707
|
+
if (index === -1) {
|
|
708
|
+
return null;
|
|
709
|
+
}
|
|
710
|
+
const parts = normalized.slice(index + marker.length).split('/');
|
|
711
|
+
if (!parts[0]) {
|
|
712
|
+
return null;
|
|
713
|
+
}
|
|
714
|
+
return parts[0].startsWith('@')
|
|
715
|
+
? [parts[0], parts[1]].filter(Boolean).join('/')
|
|
716
|
+
: parts[0];
|
|
717
|
+
}
|
|
718
|
+
function getStableInteropChunkName(id) {
|
|
719
|
+
const packageName = getNodeModulePackageName(id);
|
|
720
|
+
if (!packageName) {
|
|
721
|
+
return undefined;
|
|
722
|
+
}
|
|
723
|
+
if (packageName === 'codemirror' ||
|
|
724
|
+
packageName === '@replit/codemirror-vim' ||
|
|
725
|
+
packageName.startsWith('@codemirror/') ||
|
|
726
|
+
packageName.startsWith('@lezer/') ||
|
|
727
|
+
packageName.startsWith('@codesandbox/sandpack') ||
|
|
728
|
+
packageName === '@codesandbox/nodebox' ||
|
|
729
|
+
packageName === '@marijn/find-cluster-break' ||
|
|
730
|
+
packageName === 'crelt' ||
|
|
731
|
+
packageName === 'style-mod' ||
|
|
732
|
+
packageName === 'w3c-keyname') {
|
|
733
|
+
return 'vendor-codemirror';
|
|
734
|
+
}
|
|
735
|
+
return undefined;
|
|
736
|
+
}
|
|
737
|
+
function createStableInteropManualChunks(manualChunks) {
|
|
738
|
+
return (id, meta) => getStableInteropChunkName(id) || manualChunks(id, meta);
|
|
739
|
+
}
|
|
694
740
|
function createOptimizeDepsExclude(config) {
|
|
695
741
|
return unique([
|
|
696
742
|
...(config.optimizeDeps?.exclude || []),
|
|
@@ -1165,6 +1211,7 @@ export function fileViewerRenderers(options = {}) {
|
|
|
1165
1211
|
const selectedPackages = collectSelectedPackages(selection, autoPresetIds);
|
|
1166
1212
|
const dependencyAnchorPackages = collectDependencyAnchorPackages(selection, autoPresetIds);
|
|
1167
1213
|
const optimizeDepsExclude = createOptimizeDepsExclude(userConfig);
|
|
1214
|
+
const manualChunksFunction = getManualChunksFunction(userConfig);
|
|
1168
1215
|
const nextConfig = {
|
|
1169
1216
|
optimizeDeps: {
|
|
1170
1217
|
exclude: optimizeDepsExclude,
|
|
@@ -1177,6 +1224,18 @@ export function fileViewerRenderers(options = {}) {
|
|
|
1177
1224
|
]
|
|
1178
1225
|
}
|
|
1179
1226
|
};
|
|
1227
|
+
if (manualChunksFunction && options.stabilizeInteropChunks !== false) {
|
|
1228
|
+
return {
|
|
1229
|
+
...nextConfig,
|
|
1230
|
+
build: {
|
|
1231
|
+
rollupOptions: {
|
|
1232
|
+
output: {
|
|
1233
|
+
manualChunks: createStableInteropManualChunks(manualChunksFunction)
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1180
1239
|
if ((options.chunkStrategy || 'renderer') === 'none' || hasManualChunks(userConfig)) {
|
|
1181
1240
|
return nextConfig;
|
|
1182
1241
|
}
|
package/package.json
CHANGED