@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.
|
@@ -10,44 +10,46 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
// eslint-disable-next-line import/no-unresolved
|
|
11
11
|
// import typescript from '@rollup/plugin-typescript';
|
|
12
12
|
import { readFileSync, existsSync } from 'fs';
|
|
13
|
+
import camelCase from 'lodash/camelCase';
|
|
14
|
+
import upperFirst from 'lodash/upperFirst';
|
|
13
15
|
import * as path from 'path';
|
|
14
16
|
import externalGlobals from 'rollup-plugin-external-globals';
|
|
15
17
|
import { joinURL } from 'ufo';
|
|
16
18
|
import pages, { DefaultPageStrategy } from 'vite-plugin-react-pages';
|
|
17
19
|
import { findComponentFiles, setBlockEntryFilesPattern, getBlockEntryFilesPattern, getBlockName, logger, } from '../utils/helper';
|
|
18
20
|
import { initHtmlPreviewTransformPlugin, VIRTUAL_MODULE_ID, readHtmlFiles, generateComponent, } from './vite-plugin-html-transform';
|
|
19
|
-
const BUILTIN_MODULES_VAR = '__PAGES_KIT_BUILTIN_MODULES__';
|
|
21
|
+
// const BUILTIN_MODULES_VAR = '__PAGES_KIT_BUILTIN_MODULES__';
|
|
20
22
|
// import initRemoteScriptLocalizerPlugin from './vite-plugin-remote-script-localizer';
|
|
21
23
|
const defaultBlockExternals = {
|
|
22
24
|
// 核心 React 相关
|
|
23
|
-
react:
|
|
24
|
-
'react-dom':
|
|
25
|
-
'react-router-dom':
|
|
26
|
-
'react-hook-form': `window
|
|
27
|
-
'react-wrap-balancer': `window
|
|
28
|
-
// ArcBlock 相关
|
|
29
|
-
'@arcblock/ux': `window
|
|
30
|
-
'@arcblock/did-connect/lib/Session': `window
|
|
31
|
-
'@arcblock/ux/lib/Locale/context': `window
|
|
32
|
-
// MUI 相关
|
|
33
|
-
// '@mui/material': `window
|
|
34
|
-
// '@mui/lab': `window
|
|
35
|
-
// 其他工具库
|
|
36
|
-
dayjs: `window
|
|
37
|
-
zustand: `window
|
|
38
|
-
'zustand/middleware/immer': `window
|
|
39
|
-
immer: `window
|
|
40
|
-
stream: `window
|
|
41
|
-
'@iconify/react': `window
|
|
42
|
-
// 页面相关组件
|
|
43
|
-
'@blocklet/pages-kit/builtin/components': `window
|
|
44
|
-
'@blocklet/pages-kit/builtin/page/header': `window
|
|
45
|
-
'@blocklet/pages-kit/builtin/pages-kit': `window
|
|
46
|
-
// 异步组件
|
|
47
|
-
'react-markdown': `window
|
|
48
|
-
'react-syntax-highlighter': `window
|
|
49
|
-
'react-scroll-to-bottom': `window
|
|
50
|
-
// 浏览器原生
|
|
25
|
+
react: `@blocklet/pages-kit/builtin/react`,
|
|
26
|
+
// 'react-dom': `@blocklet/pages-kit/builtin/react-dom`,
|
|
27
|
+
'react-router-dom': `@blocklet/pages-kit/builtin/react-router-dom`,
|
|
28
|
+
// 'react-hook-form': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/react-hook-form"]`,
|
|
29
|
+
// 'react-wrap-balancer': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/react-wrap-balancer"]`,
|
|
30
|
+
// // ArcBlock 相关
|
|
31
|
+
// '@arcblock/ux': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/arcblock/ux"]`,
|
|
32
|
+
// '@arcblock/did-connect/lib/Session': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/session"]`,
|
|
33
|
+
// '@arcblock/ux/lib/Locale/context': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/locale"]`,
|
|
34
|
+
// // MUI 相关
|
|
35
|
+
// // '@mui/material': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/mui/material"]`,
|
|
36
|
+
// // '@mui/lab': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/mui/lab"]`,
|
|
37
|
+
// // 其他工具库
|
|
38
|
+
// dayjs: `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/dayjs"]`,
|
|
39
|
+
// zustand: `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/zustand"]`,
|
|
40
|
+
// 'zustand/middleware/immer': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/zustand/middleware/immer"]`,
|
|
41
|
+
// immer: `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/immer"]`,
|
|
42
|
+
// stream: `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/stream"]`,
|
|
43
|
+
// '@iconify/react': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/iconify/react"]`,
|
|
44
|
+
// // 页面相关组件
|
|
45
|
+
// '@blocklet/pages-kit/builtin/components': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/components"]`,
|
|
46
|
+
// '@blocklet/pages-kit/builtin/page/header': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/page/header"]`,
|
|
47
|
+
// '@blocklet/pages-kit/builtin/pages-kit': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/pages-kit"]`,
|
|
48
|
+
// // 异步组件
|
|
49
|
+
// 'react-markdown': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/async/react-markdown"]`,
|
|
50
|
+
// 'react-syntax-highlighter': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/async/react-syntax-highlighter"]`,
|
|
51
|
+
// 'react-scroll-to-bottom': `window.${BUILTIN_MODULES_VAR}.modules["@blocklet/pages-kit/builtin/async/react-scroll-to-bottom"]`,
|
|
52
|
+
// // 浏览器原生
|
|
51
53
|
crypto: 'window.crypto',
|
|
52
54
|
};
|
|
53
55
|
export function initBlockStudioPlugins(options) {
|
|
@@ -72,6 +74,13 @@ export function initBlockStudioPlugins(options) {
|
|
|
72
74
|
pagesDir,
|
|
73
75
|
blockExternals: externalMappings, // 添加日志输出
|
|
74
76
|
});
|
|
77
|
+
// 为 globals 创建一个无前缀的版本
|
|
78
|
+
const externalMappingsWithoutWindow = Object.fromEntries(Object.entries(externalMappings).filter(([, value]) => !value.startsWith('window.')));
|
|
79
|
+
const externalMappingsWithWindow = Object.fromEntries(Object.entries(externalMappings).filter(([, value]) => value.startsWith('window.')));
|
|
80
|
+
console.warn({
|
|
81
|
+
externalMappingsWithoutWindow,
|
|
82
|
+
externalMappingsWithWindow,
|
|
83
|
+
});
|
|
75
84
|
return [
|
|
76
85
|
// {
|
|
77
86
|
// name: 'vite-plugin-block-studio-dev',
|
|
@@ -89,6 +98,7 @@ export function initBlockStudioPlugins(options) {
|
|
|
89
98
|
// },
|
|
90
99
|
{
|
|
91
100
|
name: 'vite-plugin-block-studio-build',
|
|
101
|
+
apply: 'build',
|
|
92
102
|
enforce: 'pre',
|
|
93
103
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
94
104
|
config(_config) {
|
|
@@ -111,39 +121,32 @@ export function initBlockStudioPlugins(options) {
|
|
|
111
121
|
.filter(Boolean)
|
|
112
122
|
.filter(([blockName]) => !filterModules || filterModules.includes(blockName || ''));
|
|
113
123
|
const multiMode = entryList.length > 1;
|
|
114
|
-
// 将 externalGlobals 添加到插件中
|
|
115
|
-
const plugins = [...(_config.plugins || []), externalGlobals(externalMappings)];
|
|
116
|
-
// 为 globals 创建一个无前缀的版本
|
|
117
|
-
const externalMappingsWithoutWindow = Object.fromEntries(Object.entries(externalMappings).map(([key, value]) => {
|
|
118
|
-
// 移除 "window." 前缀
|
|
119
|
-
const globalName = String(value).replace(/^window\./, '');
|
|
120
|
-
return [key, globalName];
|
|
121
|
-
}));
|
|
122
124
|
return {
|
|
123
|
-
plugins,
|
|
124
125
|
build: Object.assign(Object.assign({}, _config === null || _config === void 0 ? void 0 : _config.build), { cssCodeSplit: false, lib: {
|
|
125
126
|
name,
|
|
126
127
|
entry: Object.assign({}, Object.fromEntries(entryList)),
|
|
127
128
|
formats: ['es', !multiMode ? 'umd' : 'cjs'],
|
|
128
129
|
fileName: (format, entryName) => `${format}/${entryName}.js`,
|
|
129
|
-
}, rollupOptions: Object.assign(Object.assign({}, (_b = _config === null || _config === void 0 ? void 0 : _config.build) === null || _b === void 0 ? void 0 : _b.rollupOptions), { external: (
|
|
130
|
-
// 将 externalMappings 中的键也添加到 external 中
|
|
131
|
-
const skip = [...Object.keys(externalMappings)];
|
|
132
|
-
if (skip.some((s) => id === s || id.startsWith(`${s}/`))) {
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
return false;
|
|
136
|
-
}, 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: () => {
|
|
130
|
+
}, 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: () => {
|
|
137
131
|
return '[format]/_chunks/[name]-[hash].js';
|
|
138
132
|
},
|
|
139
133
|
// 使用没有 window. 前缀的映射用于 globals 配置
|
|
140
|
-
globals:
|
|
134
|
+
globals: Object.fromEntries(Object.entries(externalMappings).map(([key]) => {
|
|
135
|
+
// 移除 "window." 前缀并转换为首字母大写的驼峰式
|
|
136
|
+
const rawName = String(key);
|
|
137
|
+
const globalName = upperFirst(camelCase(rawName));
|
|
138
|
+
return [key, globalName];
|
|
139
|
+
})),
|
|
141
140
|
// 确保正确处理命名导出和默认导出
|
|
142
|
-
interop: 'auto' }) }) }),
|
|
141
|
+
interop: 'auto', paths: externalMappingsWithoutWindow }) }) }),
|
|
143
142
|
};
|
|
144
143
|
});
|
|
145
144
|
},
|
|
145
|
+
configResolved(config) {
|
|
146
|
+
console.info(config.build.rollupOptions);
|
|
147
|
+
},
|
|
146
148
|
},
|
|
149
|
+
Object.assign(Object.assign({}, externalGlobals(externalMappingsWithWindow)), { apply: 'build', enforce: 'post' }),
|
|
147
150
|
// @ts-ignore
|
|
148
151
|
pages({
|
|
149
152
|
pagesDir,
|