@blocklet/pages-kit-block-studio 0.1.34 → 0.1.36
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/lib/cjs/plugins/vite-plugin-block-studio.js +68 -21
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/plugins/vite-plugin-block-studio.js +65 -21
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/types/plugins/vite-plugin-block-studio.d.ts +1 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -4
|
@@ -41,20 +41,67 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
41
41
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
44
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
48
|
exports.initBlockStudioPlugins = initBlockStudioPlugins;
|
|
46
49
|
// eslint-disable-next-line import/no-unresolved
|
|
47
50
|
// import typescript from '@rollup/plugin-typescript';
|
|
48
51
|
const fs_1 = require("fs");
|
|
49
52
|
const path = __importStar(require("path"));
|
|
53
|
+
const rollup_plugin_external_globals_1 = __importDefault(require("rollup-plugin-external-globals"));
|
|
50
54
|
const ufo_1 = require("ufo");
|
|
51
55
|
const vite_plugin_react_pages_1 = __importStar(require("vite-plugin-react-pages"));
|
|
52
56
|
const helper_1 = require("../utils/helper");
|
|
53
57
|
const vite_plugin_html_transform_1 = require("./vite-plugin-html-transform");
|
|
58
|
+
const BUILTIN_MODULES_VAR = '__PAGES_KIT_BUILTIN_MODULES__';
|
|
54
59
|
// import initRemoteScriptLocalizerPlugin from './vite-plugin-remote-script-localizer';
|
|
60
|
+
const defaultBlockExternals = {
|
|
61
|
+
// 核心 React 相关
|
|
62
|
+
react: `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/react"]`,
|
|
63
|
+
'react-dom': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/react-dom"]`,
|
|
64
|
+
'react-router-dom': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/react-router-dom"]`,
|
|
65
|
+
'react-hook-form': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/react-hook-form"]`,
|
|
66
|
+
'react-wrap-balancer': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/react-wrap-balancer"]`,
|
|
67
|
+
// ArcBlock 相关
|
|
68
|
+
'@arcblock/ux': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/arcblock/ux"]`,
|
|
69
|
+
'@arcblock/did-connect/lib/Session': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/session"]`,
|
|
70
|
+
'@arcblock/ux/lib/Locale/context': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/locale"]`,
|
|
71
|
+
// MUI 相关
|
|
72
|
+
// '@mui/material': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/mui/material"]`,
|
|
73
|
+
// '@mui/lab': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/mui/lab"]`,
|
|
74
|
+
// 其他工具库
|
|
75
|
+
dayjs: `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/dayjs"]`,
|
|
76
|
+
zustand: `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/zustand"]`,
|
|
77
|
+
'zustand/middleware/immer': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/zustand/middleware/immer"]`,
|
|
78
|
+
immer: `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/immer"]`,
|
|
79
|
+
stream: `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/stream"]`,
|
|
80
|
+
'@iconify/react': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/iconify/react"]`,
|
|
81
|
+
// 页面相关组件
|
|
82
|
+
'@blocklet/pages-kit/builtin/components': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/components"]`,
|
|
83
|
+
'@blocklet/pages-kit/builtin/page/header': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/page/header"]`,
|
|
84
|
+
'@blocklet/pages-kit/builtin/pages-kit': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/pages-kit"]`,
|
|
85
|
+
// 异步组件
|
|
86
|
+
'react-markdown': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/async/react-markdown"]`,
|
|
87
|
+
'react-syntax-highlighter': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/async/react-syntax-highlighter"]`,
|
|
88
|
+
'react-scroll-to-bottom': `window[${BUILTIN_MODULES_VAR}].modules["@blocklet/pages-kit/builtin/async/react-scroll-to-bottom"]`,
|
|
89
|
+
// 浏览器原生
|
|
90
|
+
crypto: 'window.crypto',
|
|
91
|
+
};
|
|
55
92
|
function initBlockStudioPlugins(options) {
|
|
56
93
|
const workingDir = (options === null || options === void 0 ? void 0 : options.cwd) || process.cwd();
|
|
57
94
|
const entryFilesPattern = (options === null || options === void 0 ? void 0 : options.entryFilesPattern) || (0, helper_1.getBlockEntryFilesPattern)();
|
|
95
|
+
// 处理 blockExternals 参数
|
|
96
|
+
let externalMappings = defaultBlockExternals;
|
|
97
|
+
if (typeof (options === null || options === void 0 ? void 0 : options.blockExternals) === 'function') {
|
|
98
|
+
// 如果是函数,则调用它并传入默认值
|
|
99
|
+
externalMappings = options.blockExternals(defaultBlockExternals);
|
|
100
|
+
}
|
|
101
|
+
else if (options === null || options === void 0 ? void 0 : options.blockExternals) {
|
|
102
|
+
// 如果是对象,直接使用
|
|
103
|
+
externalMappings = options.blockExternals;
|
|
104
|
+
}
|
|
58
105
|
(0, helper_1.setBlockEntryFilesPattern)(entryFilesPattern);
|
|
59
106
|
// fallback to __dirname if _theme.tsx not exists
|
|
60
107
|
const pagesDir = (0, fs_1.existsSync)(path.join(workingDir, '_theme.tsx')) ? workingDir : __dirname.replace('cjs', 'esm');
|
|
@@ -62,6 +109,7 @@ function initBlockStudioPlugins(options) {
|
|
|
62
109
|
cwd: workingDir,
|
|
63
110
|
entryFilesPattern: (0, helper_1.getBlockEntryFilesPattern)(),
|
|
64
111
|
pagesDir,
|
|
112
|
+
blockExternals: externalMappings, // 添加日志输出
|
|
65
113
|
});
|
|
66
114
|
return [
|
|
67
115
|
// {
|
|
@@ -84,7 +132,7 @@ function initBlockStudioPlugins(options) {
|
|
|
84
132
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
85
133
|
config(_config) {
|
|
86
134
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
var _a;
|
|
135
|
+
var _a, _b, _c, _d;
|
|
88
136
|
const filterModules = process.argv.includes('--filter')
|
|
89
137
|
? (_a = process.argv[process.argv.indexOf('--filter') + 1]) === null || _a === void 0 ? void 0 : _a.split(',')
|
|
90
138
|
: null;
|
|
@@ -102,36 +150,35 @@ function initBlockStudioPlugins(options) {
|
|
|
102
150
|
.filter(Boolean)
|
|
103
151
|
.filter(([blockName]) => !filterModules || filterModules.includes(blockName || ''));
|
|
104
152
|
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
|
+
}));
|
|
105
161
|
return {
|
|
106
|
-
|
|
162
|
+
plugins,
|
|
163
|
+
build: Object.assign(Object.assign({}, _config === null || _config === void 0 ? void 0 : _config.build), { cssCodeSplit: false, lib: {
|
|
107
164
|
name,
|
|
108
165
|
entry: Object.assign({}, Object.fromEntries(entryList)),
|
|
109
166
|
formats: ['es', !multiMode ? 'umd' : 'cjs'],
|
|
110
167
|
fileName: (format, entryName) => `${format}/${entryName}.js`,
|
|
111
|
-
}, rollupOptions: {
|
|
112
|
-
|
|
113
|
-
const skip = [
|
|
114
|
-
if (skip.some((s) => id === s)) {
|
|
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: (id) => {
|
|
169
|
+
// 将 externalMappings 中的键也添加到 external 中
|
|
170
|
+
const skip = [...Object.keys(externalMappings)];
|
|
171
|
+
if (skip.some((s) => id === s || id.startsWith(`${s}/`))) {
|
|
115
172
|
return true;
|
|
116
173
|
}
|
|
117
174
|
return false;
|
|
118
|
-
},
|
|
119
|
-
output: {
|
|
120
|
-
chunkFileNames: () => {
|
|
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: () => {
|
|
121
176
|
return '[format]/_chunks/[name]-[hash].js';
|
|
122
|
-
},
|
|
123
|
-
//
|
|
124
|
-
globals:
|
|
125
|
-
react: 'React',
|
|
126
|
-
},
|
|
127
|
-
paths: {
|
|
128
|
-
// Redirect 'react' imports to '@blocklet/pages-kit/builtin/react'
|
|
129
|
-
react: '@blocklet/pages-kit/builtin/react',
|
|
130
|
-
},
|
|
177
|
+
},
|
|
178
|
+
// 使用没有 window. 前缀的映射用于 globals 配置
|
|
179
|
+
globals: externalMappingsWithoutWindow,
|
|
131
180
|
// 确保正确处理命名导出和默认导出
|
|
132
|
-
interop: 'auto',
|
|
133
|
-
},
|
|
134
|
-
} }, _config === null || _config === void 0 ? void 0 : _config.build),
|
|
181
|
+
interop: 'auto' }) }) }),
|
|
135
182
|
};
|
|
136
183
|
});
|
|
137
184
|
},
|