@blocklet/pages-kit-block-studio 0.1.36 → 0.1.38
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.
|
@@ -49,44 +49,46 @@ exports.initBlockStudioPlugins = initBlockStudioPlugins;
|
|
|
49
49
|
// eslint-disable-next-line import/no-unresolved
|
|
50
50
|
// import typescript from '@rollup/plugin-typescript';
|
|
51
51
|
const fs_1 = require("fs");
|
|
52
|
+
const camelCase_1 = __importDefault(require("lodash/camelCase"));
|
|
53
|
+
const upperFirst_1 = __importDefault(require("lodash/upperFirst"));
|
|
52
54
|
const path = __importStar(require("path"));
|
|
53
55
|
const rollup_plugin_external_globals_1 = __importDefault(require("rollup-plugin-external-globals"));
|
|
54
56
|
const ufo_1 = require("ufo");
|
|
55
57
|
const vite_plugin_react_pages_1 = __importStar(require("vite-plugin-react-pages"));
|
|
56
58
|
const helper_1 = require("../utils/helper");
|
|
57
59
|
const vite_plugin_html_transform_1 = require("./vite-plugin-html-transform");
|
|
58
|
-
const BUILTIN_MODULES_VAR = '__PAGES_KIT_BUILTIN_MODULES__';
|
|
60
|
+
// const BUILTIN_MODULES_VAR = '__PAGES_KIT_BUILTIN_MODULES__';
|
|
59
61
|
// import initRemoteScriptLocalizerPlugin from './vite-plugin-remote-script-localizer';
|
|
60
62
|
const defaultBlockExternals = {
|
|
61
63
|
// 核心 React 相关
|
|
62
|
-
react:
|
|
63
|
-
'react-dom':
|
|
64
|
-
'react-router-dom':
|
|
65
|
-
'react-hook-form': `window
|
|
66
|
-
'react-wrap-balancer': `window
|
|
67
|
-
// ArcBlock 相关
|
|
68
|
-
'@arcblock/ux': `window
|
|
69
|
-
'@arcblock/did-connect/lib/Session': `window
|
|
70
|
-
'@arcblock/ux/lib/Locale/context': `window
|
|
71
|
-
// MUI 相关
|
|
72
|
-
// '@mui/material': `window
|
|
73
|
-
// '@mui/lab': `window
|
|
74
|
-
// 其他工具库
|
|
75
|
-
dayjs: `window
|
|
76
|
-
zustand: `window
|
|
77
|
-
'zustand/middleware/immer': `window
|
|
78
|
-
immer: `window
|
|
79
|
-
stream: `window
|
|
80
|
-
'@iconify/react': `window
|
|
81
|
-
// 页面相关组件
|
|
82
|
-
'@blocklet/pages-kit/builtin/components': `window
|
|
83
|
-
'@blocklet/pages-kit/builtin/page/header': `window
|
|
84
|
-
'@blocklet/pages-kit/builtin/pages-kit': `window
|
|
85
|
-
// 异步组件
|
|
86
|
-
'react-markdown': `window
|
|
87
|
-
'react-syntax-highlighter': `window
|
|
88
|
-
'react-scroll-to-bottom': `window
|
|
89
|
-
// 浏览器原生
|
|
64
|
+
react: `@blocklet/pages-kit/builtin/react`,
|
|
65
|
+
// 'react-dom': `@blocklet/pages-kit/builtin/react-dom`,
|
|
66
|
+
'react-router-dom': `@blocklet/pages-kit/builtin/react-router-dom`,
|
|
67
|
+
// 'react-hook-form': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/react-hook-form"]`,
|
|
68
|
+
// 'react-wrap-balancer': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/react-wrap-balancer"]`,
|
|
69
|
+
// // ArcBlock 相关
|
|
70
|
+
// '@arcblock/ux': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/arcblock/ux"]`,
|
|
71
|
+
// '@arcblock/did-connect/lib/Session': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/session"]`,
|
|
72
|
+
// '@arcblock/ux/lib/Locale/context': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/locale"]`,
|
|
73
|
+
// // MUI 相关
|
|
74
|
+
// // '@mui/material': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/mui/material"]`,
|
|
75
|
+
// // '@mui/lab': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/mui/lab"]`,
|
|
76
|
+
// // 其他工具库
|
|
77
|
+
// dayjs: `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/dayjs"]`,
|
|
78
|
+
// zustand: `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/zustand"]`,
|
|
79
|
+
// 'zustand/middleware/immer': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/zustand/middleware/immer"]`,
|
|
80
|
+
// immer: `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/immer"]`,
|
|
81
|
+
// stream: `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/stream"]`,
|
|
82
|
+
// '@iconify/react': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/iconify/react"]`,
|
|
83
|
+
// // 页面相关组件
|
|
84
|
+
// '@blocklet/pages-kit/builtin/components': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/components"]`,
|
|
85
|
+
// '@blocklet/pages-kit/builtin/page/header': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/page/header"]`,
|
|
86
|
+
// '@blocklet/pages-kit/builtin/pages-kit': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/pages-kit"]`,
|
|
87
|
+
// // 异步组件
|
|
88
|
+
// 'react-markdown': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/async/react-markdown"]`,
|
|
89
|
+
// 'react-syntax-highlighter': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/async/react-syntax-highlighter"]`,
|
|
90
|
+
// 'react-scroll-to-bottom': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/async/react-scroll-to-bottom"]`,
|
|
91
|
+
// // 浏览器原生
|
|
90
92
|
crypto: 'window.crypto',
|
|
91
93
|
};
|
|
92
94
|
function initBlockStudioPlugins(options) {
|
|
@@ -111,6 +113,13 @@ function initBlockStudioPlugins(options) {
|
|
|
111
113
|
pagesDir,
|
|
112
114
|
blockExternals: externalMappings, // 添加日志输出
|
|
113
115
|
});
|
|
116
|
+
// 为 globals 创建一个无前缀的版本
|
|
117
|
+
const externalMappingsWithoutWindow = Object.fromEntries(Object.entries(externalMappings).filter(([, value]) => !value.startsWith('window.')));
|
|
118
|
+
const externalMappingsWithWindow = Object.fromEntries(Object.entries(externalMappings).filter(([, value]) => value.startsWith('window.')));
|
|
119
|
+
console.warn({
|
|
120
|
+
externalMappingsWithoutWindow,
|
|
121
|
+
externalMappingsWithWindow,
|
|
122
|
+
});
|
|
114
123
|
return [
|
|
115
124
|
// {
|
|
116
125
|
// name: 'vite-plugin-block-studio-dev',
|
|
@@ -128,6 +137,7 @@ function initBlockStudioPlugins(options) {
|
|
|
128
137
|
// },
|
|
129
138
|
{
|
|
130
139
|
name: 'vite-plugin-block-studio-build',
|
|
140
|
+
apply: 'build',
|
|
131
141
|
enforce: 'pre',
|
|
132
142
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
133
143
|
config(_config) {
|
|
@@ -150,39 +160,32 @@ function initBlockStudioPlugins(options) {
|
|
|
150
160
|
.filter(Boolean)
|
|
151
161
|
.filter(([blockName]) => !filterModules || filterModules.includes(blockName || ''));
|
|
152
162
|
const multiMode = entryList.length > 1;
|
|
153
|
-
// 将 externalGlobals 添加到插件中
|
|
154
|
-
const plugins = [...(_config.plugins || []), (0, rollup_plugin_external_globals_1.default)(externalMappings)];
|
|
155
|
-
// 为 globals 创建一个无前缀的版本
|
|
156
|
-
const externalMappingsWithoutWindow = Object.fromEntries(Object.entries(externalMappings).map(([key, value]) => {
|
|
157
|
-
// 移除 "window." 前缀
|
|
158
|
-
const globalName = String(value).replace(/^window\./, '');
|
|
159
|
-
return [key, globalName];
|
|
160
|
-
}));
|
|
161
163
|
return {
|
|
162
|
-
plugins,
|
|
163
164
|
build: Object.assign(Object.assign({}, _config === null || _config === void 0 ? void 0 : _config.build), { cssCodeSplit: false, lib: {
|
|
164
165
|
name,
|
|
165
166
|
entry: Object.assign({}, Object.fromEntries(entryList)),
|
|
166
167
|
formats: ['es', !multiMode ? 'umd' : 'cjs'],
|
|
167
168
|
fileName: (format, entryName) => `${format}/${entryName}.js`,
|
|
168
|
-
}, rollupOptions: Object.assign(Object.assign({}, (_b = _config === null || _config === void 0 ? void 0 : _config.build) === null || _b === void 0 ? void 0 : _b.rollupOptions), { external: (
|
|
169
|
-
// 将 externalMappings 中的键也添加到 external 中
|
|
170
|
-
const skip = [...Object.keys(externalMappings)];
|
|
171
|
-
if (skip.some((s) => id === s || id.startsWith(`${s}/`))) {
|
|
172
|
-
return true;
|
|
173
|
-
}
|
|
174
|
-
return false;
|
|
175
|
-
}, output: Object.assign(Object.assign({}, (_d = (_c = _config === null || _config === void 0 ? void 0 : _config.build) === null || _c === void 0 ? void 0 : _c.rollupOptions) === null || _d === void 0 ? void 0 : _d.output), { chunkFileNames: () => {
|
|
169
|
+
}, rollupOptions: Object.assign(Object.assign({}, (_b = _config === null || _config === void 0 ? void 0 : _config.build) === null || _b === void 0 ? void 0 : _b.rollupOptions), { external: [...Object.keys(externalMappings)], output: Object.assign(Object.assign({}, (_d = (_c = _config === null || _config === void 0 ? void 0 : _config.build) === null || _c === void 0 ? void 0 : _c.rollupOptions) === null || _d === void 0 ? void 0 : _d.output), { chunkFileNames: () => {
|
|
176
170
|
return '[format]/_chunks/[name]-[hash].js';
|
|
177
171
|
},
|
|
178
172
|
// 使用没有 window. 前缀的映射用于 globals 配置
|
|
179
|
-
globals:
|
|
173
|
+
globals: Object.fromEntries(Object.entries(externalMappings).map(([key]) => {
|
|
174
|
+
// 移除 "window." 前缀并转换为首字母大写的驼峰式
|
|
175
|
+
const rawName = String(key);
|
|
176
|
+
const globalName = (0, upperFirst_1.default)((0, camelCase_1.default)(rawName));
|
|
177
|
+
return [key, globalName];
|
|
178
|
+
})),
|
|
180
179
|
// 确保正确处理命名导出和默认导出
|
|
181
|
-
interop: 'auto' }) }) }),
|
|
180
|
+
interop: 'auto', paths: externalMappingsWithoutWindow }) }) }),
|
|
182
181
|
};
|
|
183
182
|
});
|
|
184
183
|
},
|
|
184
|
+
configResolved(config) {
|
|
185
|
+
console.info(config.build.rollupOptions);
|
|
186
|
+
},
|
|
185
187
|
},
|
|
188
|
+
Object.assign(Object.assign({}, (0, rollup_plugin_external_globals_1.default)(externalMappingsWithWindow)), { apply: 'build', enforce: 'post' }),
|
|
186
189
|
// @ts-ignore
|
|
187
190
|
(0, vite_plugin_react_pages_1.default)({
|
|
188
191
|
pagesDir,
|