Skip to content
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7dd68df
feat: 给image增加lego模式,Stencil及React版本添均加
Sep 1, 2025
822fef9
chore(release): publish 4.1.6-beta.1 --tag=beta
Sep 1, 2025
6b39b8f
chore(release): publish 4.1.7-beta.0 --tag=beta
Sep 2, 2025
e7eec36
feat(taro-components-react): 新增 Button 组件对 TD 端的支持
zhianziqiyan Sep 2, 2025
ebab586
Merge pull request #18288 from zhianziqiyan/feat/4.1.7-react-button
Muyouz Sep 2, 2025
03531be
chore(release): publish 4.1.7-alpha.0 --tag=alpha
Sep 2, 2025
be4f3c6
feat: lego模式增加lang参数
Sep 3, 2025
1bd6ebb
chore(release): publish 4.1.7-beta.1 --tag=beta
Sep 3, 2025
f2a04b1
feat: 删除旧版为端侧增加的打包配置,新增original打包配置
Sep 9, 2025
a797f58
chore(release): publish 4.1.7-beta.2 --tag=beta
Sep 9, 2025
fdd5769
fix: 修复依赖
Sep 9, 2025
a152ec6
fix: 还原版本号
Sep 9, 2025
8d9f932
chore(release): publish 4.1.7-beta.2 --tag=beta
Sep 9, 2025
7f72d4e
fix: 修复版本异常
Sep 9, 2025
5628cc1
chore(release): publish 4.1.7-beta.2 --tag=beta
Sep 9, 2025
66ce2dd
fix: 修复依赖打包异常
Sep 9, 2025
76d15eb
chore(release): publish 4.1.7-beta.2 --tag=beta
Sep 9, 2025
b7c86e5
fix: 格式化修改
Sep 9, 2025
fbecd04
fix: 修复cjs中引入的样式失效的问题
Sep 15, 2025
7bbf244
Merge branch 'feat/4.1.7-react-button' into feat/4.1.7-mian-feat
Sep 15, 2025
7dfe8cb
chore(release): publish 4.1.7-beta.3 --tag=beta
Sep 15, 2025
3e8127e
fix: 修改original产物
Sep 21, 2025
dedc598
chore(release): publish 4.1.7-beta.4 --tag=beta
Sep 21, 2025
dbb15fa
fix: 修复依赖问题
Sep 21, 2025
ee7af75
fix: 回退版本
Sep 21, 2025
60a4d9f
chore(release): publish 4.1.7-beta.4 --tag=beta
Sep 21, 2025
d87fbd0
fix: 修复版本号
Sep 22, 2025
2bef43c
fix: 还原配置文件
Sep 22, 2025
cab108a
fix: 修复异常依赖问题
Sep 22, 2025
8257553
Merge branch 'main' into feat/4.1.7-mian-feat
Single-Dancer Sep 22, 2025
250ced4
fix: 修改eslint问题
Sep 22, 2025
abf2b25
修改依赖版本
Muyouz Sep 22, 2025
222d9ca
fix: 修改依赖
Sep 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"conventional-changelog-cli": "^2.0.1",
"core-js": "^3.6.5",
"cross-env": "^7.0.2",
"dotenv": "^16.4.7",
"escodegen": "^2.0.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^6.4.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/taro-components-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.24.4",
"@tarojs/components": "workspace:*",
"@tarojs/shared": "workspace:*",
"@tarojs/taro": "workspace:*",
"@tarojs/components": "4.1.7-beta.3",
"@tarojs/shared": "4.1.7-beta.3",
"@tarojs/taro": "4.1.7-beta.3",
"classnames": "^2.2.5",
"identity-obj-proxy": "^3.0.0",
"swiper": "11.1.15",
Expand All @@ -49,8 +49,8 @@
"@babel/plugin-transform-runtime": "^7.24.1",
"@babel/preset-react": "^7.24.1",
"@babel/preset-typescript": "^7.24.1",
"@tarojs/helper": "workspace:*",
"@tarojs/runtime": "workspace:*",
"@tarojs/helper": "4.1.7-beta.3",
"@tarojs/runtime": "4.1.7-beta.3",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.1",
Expand Down
273 changes: 212 additions & 61 deletions packages/taro-components-react/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,188 @@ import { nodeResolve } from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import ts from '@rollup/plugin-typescript'
import { recursiveMerge } from '@tarojs/helper'
import fs from 'fs'
import path from 'path'
Comment on lines +8 to 9
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

为后续路径修正引入 fileURLToPath,避免依赖 process.cwd()。

后面建议用配置文件所在目录来定位 src,需要先引入该 API。

-import fs from 'fs'
+import fs from 'fs'
+import { fileURLToPath } from 'node:url'
 import path from 'path'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import fs from 'fs'
import path from 'path'
import fs from 'fs'
import { fileURLToPath } from 'node:url'
import path from 'path'
🤖 Prompt for AI Agents
In packages/taro-components-react/rollup.config.mjs around lines 8-9, the config
currently imports fs and path but does not import fileURLToPath; to avoid using
process.cwd() and reliably locate the config file's directory, add an import for
fileURLToPath from 'url', derive the current file directory via
fileURLToPath(import.meta.url) and use that directory (via path.resolve(dirname,
...)) when resolving the src path for rollup inputs and other path calculations.

import { defineConfig } from 'rollup'
import externals from 'rollup-plugin-node-externals'
import postcss from 'rollup-plugin-postcss'

function getPlugins (pre = [], post = []) {
return [
// 合并 SCSS 文件到 original 构建输出目录
function mergeScssFiles() {
return {
name: 'merge-scss-files',
writeBundle(options) {
if (!options.dir?.includes('original')) return

const outputDir = options.dir
const srcDir = path.join(process.cwd(), 'src')
const componentsDir = path.join(outputDir, 'components')

Comment on lines +21 to +24
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

避免使用 process.cwd() 导致路径漂移(从仓库根执行构建会找不到 src)。

应基于 rollup 配置文件所在目录定位 src,更稳健、与 monorepo 兼容。

-      const outputDir = options.dir
-      const srcDir = path.join(process.cwd(), 'src')
+      const outputDir = options.dir
+      const pkgRoot = path.dirname(fileURLToPath(import.meta.url))
+      const srcDir = path.join(pkgRoot, 'src')
       const componentsDir = path.join(outputDir, 'components')

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/taro-components-react/rollup.config.mjs around lines 21-24, srcDir
is computed with process.cwd(), which can break when builds are run outside the
package root; replace process.cwd() with the directory of this config file by
deriving the config file path via import.meta.url (using fileURLToPath) and
path.dirname, then join that directory with 'src' (and adjust any imports to add
the fileURLToPath import). This makes path resolution deterministic and
monorepo-compatible.

if (!fs.existsSync(componentsDir)) return

fs.readdirSync(componentsDir).forEach((component) => {
const componentDir = path.join(componentsDir, component)
if (!fs.statSync(componentDir).isDirectory()) return

const styleDir = path.join(componentDir, 'style')
fs.mkdirSync(styleDir, { recursive: true })

const srcStyleDir = path.join(srcDir, 'components', component, 'style')
const indexScssPath = path.join(srcStyleDir, 'index.scss')

if (fs.existsSync(indexScssPath)) {
const mergedContent = mergeScssFile(indexScssPath, srcStyleDir)
fs.writeFileSync(path.join(styleDir, 'index.scss'), mergedContent)
}
})
},
}
}

// 递归合并 SCSS 文件内容
function mergeScssFile(filePath, baseDir, processedFiles = new Set()) {
if (processedFiles.has(filePath)) return `/* Circular import: ${path.basename(filePath)} */`

processedFiles.add(filePath)
let content = fs.readFileSync(filePath, 'utf8')

content = content.replace(/@import\s+['"]([^'"]+)['"];?/g, (match, importPath) => {
let resolvedPath = importPath.startsWith('./')
? path.resolve(path.dirname(filePath), importPath)
: path.resolve(baseDir, importPath)

if (!resolvedPath.endsWith('.scss')) resolvedPath += '.scss'

return fs.existsSync(resolvedPath)
? `/* Imported from ${importPath} */\n${mergeScssFile(resolvedPath, baseDir, processedFiles)}`
: `/* Missing: ${importPath} */`
})
Comment on lines +53 to +63
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

SCSS 解析过于简化:未覆盖多重 import、"../" 相对路径与 _partial 命名。

现有正则仅处理单个 "@import 'x'",也没考虑部分文件与 "../"。建议增强以减少漏并发出更稳定的合并结果。

-  content = content.replace(/@import\s+['"]([^'"]+)['"];?/g, (match, importPath) => {
-    let resolvedPath = importPath.startsWith('./')
-      ? path.resolve(path.dirname(filePath), importPath)
-      : path.resolve(baseDir, importPath)
-
-    if (!resolvedPath.endsWith('.scss')) resolvedPath += '.scss'
-
-    return fs.existsSync(resolvedPath)
-      ? `/* Imported from ${importPath} */\n${mergeScssFile(resolvedPath, baseDir, processedFiles)}`
-      : `/* Missing: ${importPath} */`
-  })
+  // 支持逗号分隔、"../" 相对路径与 _partial 回退
+  content = content.replace(/@import\s+((?:"[^"]+"|'[^']+')(\s*,\s*(?:"[^"]+"|'[^']+'))*)\s*;?/g, (_m, list) => {
+    const imports = list.split(/\s*,\s*/).map(s => s.slice(1, -1))
+    return imports.map((importPath) => {
+      const isRelative = importPath.startsWith('.')
+      let resolvedPath = isRelative
+        ? path.resolve(path.dirname(filePath), importPath)
+        : path.resolve(baseDir, importPath)
+      if (!resolvedPath.endsWith('.scss')) resolvedPath += '.scss'
+      // _partial 回退
+      let candidate = resolvedPath
+      if (!fs.existsSync(candidate)) {
+        const dir = path.dirname(resolvedPath)
+        const base = path.basename(resolvedPath)
+        candidate = path.join(dir, `_${base}`)
+      }
+      return fs.existsSync(candidate)
+        ? `/* Imported from ${importPath} */\n${mergeScssFile(candidate, baseDir, processedFiles)}`
+        : `/* Missing: ${importPath} */`
+    }).join('\n')
+  })

补充建议(可后续跟进):当前未处理 Sass 的 @use/@forward,新文件若采用该语法,建议保持原样或单独解析以免语义变化。

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
content = content.replace(/@import\s+['"]([^'"]+)['"];?/g, (match, importPath) => {
let resolvedPath = importPath.startsWith('./')
? path.resolve(path.dirname(filePath), importPath)
: path.resolve(baseDir, importPath)
if (!resolvedPath.endsWith('.scss')) resolvedPath += '.scss'
return fs.existsSync(resolvedPath)
? `/* Imported from ${importPath} */\n${mergeScssFile(resolvedPath, baseDir, processedFiles)}`
: `/* Missing: ${importPath} */`
})
// 支持逗号分隔、"../" 相对路径与 _partial 回退
content = content.replace(/@import\s+((?:"[^"]+"|'[^']+')(\s*,\s*(?:"[^"]+"|'[^']+'))*)\s*;?/g, (_m, list) => {
const imports = list.split(/\s*,\s*/).map(s => s.slice(1, -1))
return imports.map((importPath) => {
const isRelative = importPath.startsWith('.')
let resolvedPath = isRelative
? path.resolve(path.dirname(filePath), importPath)
: path.resolve(baseDir, importPath)
if (!resolvedPath.endsWith('.scss')) resolvedPath += '.scss'
// _partial 回退
let candidate = resolvedPath
if (!fs.existsSync(candidate)) {
const dir = path.dirname(resolvedPath)
const base = path.basename(resolvedPath)
candidate = path.join(dir, `_${base}`)
}
return fs.existsSync(candidate)
? `/* Imported from ${importPath} */\n${mergeScssFile(candidate, baseDir, processedFiles)}`
: `/* Missing: ${importPath} */`
}).join('\n')
})


processedFiles.delete(filePath)
return content
}

// 清理 original 构建中的样式文件
function fixStyleImports() {
return {
name: 'fix-style-imports',
writeBundle(options) {
if (!options.dir?.includes('original')) return

const componentsDir = path.join(options.dir, 'components')
if (!fs.existsSync(componentsDir)) return

fs.readdirSync(componentsDir).forEach((component) => {
const componentDir = path.join(componentsDir, component)
if (!fs.statSync(componentDir).isDirectory()) return

const indexJsPath = path.join(componentDir, 'index.js')
if (!fs.existsSync(indexJsPath)) return

// 确保样式 import 语句正确引用 SCSS 文件
let content = fs.readFileSync(indexJsPath, 'utf8')
// 将 .scss.js 或 .css.js 的导入改为 .scss 导入
content = content.replace(/import\s+['"]\.\/style\/index\.(scss|css)\.js['"];?\s*/g, "import './style/index.scss';\n")
fs.writeFileSync(indexJsPath, content)

// 清理 .scss.js 和 .scss.js.map 文件
const styleDir = path.join(componentDir, 'style')
if (fs.existsSync(styleDir)) {
fs.readdirSync(styleDir).forEach((file) => {
if (file.endsWith('.scss.js') || file.endsWith('.scss.js.map')) {
fs.unlinkSync(path.join(styleDir, file))
}
})
}
})
},
}
}

// 自定义样式处理插件 - 替换 rollup-plugin-styles
function customStylesPlugin() {
return {
name: 'custom-styles-plugin',
// 处理 SCSS 文件导入,让 Rollup 能够识别
load(id) {
if (id.endsWith('.scss')) {
// 返回空的 CSS 内容,让 Rollup 能够处理导入
return '/* SCSS file - processed by custom plugin */'
}
return null
},
// 在 writeBundle 阶段进行后处理
writeBundle(options) {
// 只处理 original 构建模式
if (!options.dir?.includes('original')) return

// 确保样式文件保持原始格式,不进行任何编译
const outputDir = options.dir
const componentsDir = path.join(outputDir, 'components')

if (!fs.existsSync(componentsDir)) return

// 遍历所有组件目录,确保 SCSS 文件保持原始格式
fs.readdirSync(componentsDir).forEach((component) => {
const componentDir = path.join(componentsDir, component)
if (!fs.statSync(componentDir).isDirectory()) return

const styleDir = path.join(componentDir, 'style')
if (fs.existsSync(styleDir)) {
// 清理任何可能由其他插件生成的异常文件
fs.readdirSync(styleDir).forEach((file) => {
const filePath = path.join(styleDir, file)
// 删除非 SCSS 的样式相关文件
if (file.endsWith('.css') ||
file.endsWith('.css.map') ||
file.endsWith('.scss.js') ||
file.endsWith('.scss.js.map') ||
file.endsWith('.css.js') ||
file.endsWith('.css.js.map')) {
try {
fs.unlinkSync(filePath)
} catch (error) {
console.warn(`Failed to delete file ${filePath}:`, error.message)
}
}
})
}
})
}
}
}

function getPlugins(pre = [], post = [], isOriginal = false) {
const basePlugins = [
...pre,
externals({
deps: true,
devDeps: false,
}),
nodeResolve({
preferBuiltins: false,
mainFields: ['main:h5', 'browser', 'module', 'jsnext:main', 'main']
}),
postcss({
extract: true,
inject: { insertAt: 'top' },
minimize: true,
mainFields: ['main:h5', 'browser', 'module', 'jsnext:main', 'main'],
}),
// 根据模式选择样式处理插件
isOriginal
? customStylesPlugin() // 使用自定义样式插件,保持 SCSS 原始格式
: postcss({
extract: true,
inject: { insertAt: 'top' },
minimize: true,
}),
Comment on lines +159 to +177
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

非 original 构建无法编译 SCSS:postcss 未配置 sass 预处理,将在遇到 .scss 导入时失败。

为 react/solid 构建补上 SCSS 编译(使用 sass 预处理),避免回归。

在顶部增加:

+import sass from 'sass'

替换 postcss 配置为带预处理(并建议移除注入以生成独立 CSS 文件):

-    isOriginal
-      ? customStylesPlugin() // 使用自定义样式插件,保持 SCSS 原始格式
-      : postcss({
-        extract: true,
-        inject: { insertAt: 'top' },
-        minimize: true,
-      }),
+    isOriginal
+      ? customStylesPlugin() // original:保持 SCSS 原始格式
+      : postcss({
+          extract: true,
+          minimize: true,
+          // 编译 SCSS -> CSS(依赖 `sass` 包)
+          preprocessor: (content, id) => {
+            if (!/\.scss$/i.test(id)) return { code: content }
+            const { css } = sass.compileString(content, { loadPaths: [path.dirname(id)] })
+            return { code: String(css) }
+          },
+        }),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function getPlugins(pre = [], post = [], isOriginal = false) {
const basePlugins = [
...pre,
externals({
deps: true,
devDeps: false,
}),
nodeResolve({
preferBuiltins: false,
mainFields: ['main:h5', 'browser', 'module', 'jsnext:main', 'main']
}),
postcss({
extract: true,
inject: { insertAt: 'top' },
minimize: true,
mainFields: ['main:h5', 'browser', 'module', 'jsnext:main', 'main'],
}),
// 根据模式选择样式处理插件
isOriginal
? customStylesPlugin() // 使用自定义样式插件,保持 SCSS 原始格式
: postcss({
extract: true,
inject: { insertAt: 'top' },
minimize: true,
}),
import sass from 'sass'
function getPlugins(pre = [], post = [], isOriginal = false) {
const basePlugins = [
...pre,
externals({
deps: true,
devDeps: false,
}),
nodeResolve({
preferBuiltins: false,
mainFields: ['main:h5', 'browser', 'module', 'jsnext:main', 'main'],
}),
// 根据模式选择样式处理插件
isOriginal
? customStylesPlugin() // original:保持 SCSS 原始格式
: postcss({
extract: true,
minimize: true,
// 编译 SCSS -> CSS(依赖 `sass` 包)
preprocessor: (content, id) => {
if (!/\.scss$/i.test(id)) return { code: content }
const { css } = sass.compileString(content, { loadPaths: [path.dirname(id)] })
return { code: String(css) }
},
}),
🤖 Prompt for AI Agents
In packages/taro-components-react/rollup.config.mjs around lines 159–177, the
non-original build uses postcss but doesn’t configure a Sass preprocessor, so
importing .scss fails; update the file to import/require a Sass implementation
(e.g. dart-sass) at the top and replace the current postcss(...) call with a
postcss configuration that supplies a preprocessor hooking into Sass (compile
scss to css), keep extract: true (remove inject option so CSS is emitted as
standalone files), and preserve minimize; also ensure the project
devDependencies include the chosen Sass package and postcss plugin support so
SCSS files compile during the react/solid builds.

ts(),
commonjs({
include: '../../node_modules/**'
include: '../../node_modules/**',
}),
Comment on lines +180 to 181
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

CommonJS include 路径过于具体,可能漏编译依赖(pnpm/yarn workspace 下尤甚)。

建议同时覆盖本包与工作区根的 node_modules。

-    commonjs({
-      include: '../../node_modules/**',
+    commonjs({
+      include: ['node_modules/**', '../../node_modules/**'],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
include: '../../node_modules/**',
}),
commonjs({
include: ['node_modules/**', '../../node_modules/**'],
}),
🤖 Prompt for AI Agents
In packages/taro-components-react/rollup.config.mjs around lines 135-136, the
CommonJS plugin include pattern only targets '../../node_modules/**' which is
too specific and can miss dependencies in this package's own node_modules or
workspace root (common in pnpm/yarn workspaces); update the include to cover
both locations by adding a more general node_modules pattern alongside the
existing relative path (e.g., include both 'node_modules/**' and
'../../node_modules/**') so dependencies from the package and the workspace root
are compiled.

...post
...post,
]
return basePlugins
}

function getAliasPlugin (framework) {
function getAliasPlugin(framework) {
return alias({
entries: [
{ find: /.*hooks$/, replacement: (source) => source.replace(/hooks$/, `hooks.${framework}.ts`) }
]
entries: [{ find: /.*hooks$/, replacement: (source) => source.replace(/hooks$/, `hooks.${framework}.ts`) }],
})
Comment on lines +187 to 190
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

alias 的 replacement 使用函数存在兼容性与类型风险,建议用更直接的正则替换。

使用捕获组或限定尾部替换即可实现同样效果,避免潜在运行时问题。

-function getAliasPlugin(framework) {
-  return alias({
-    entries: [{ find: /.*hooks$/, replacement: (source) => source.replace(/hooks$/, `hooks.${framework}.ts`) }],
-  })
-}
+function getAliasPlugin(framework) {
+  return alias({
+    // 仅替换末尾 hooks -> hooks.<framework>.ts
+    entries: [{ find: /hooks$/, replacement: `hooks.${framework}.ts` }],
+  })
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function getAliasPlugin(framework) {
return alias({
entries: [
{ find: /.*hooks$/, replacement: (source) => source.replace(/hooks$/, `hooks.${framework}.ts`) }
]
entries: [{ find: /.*hooks$/, replacement: (source) => source.replace(/hooks$/, `hooks.${framework}.ts`) }],
})
function getAliasPlugin(framework) {
return alias({
// 仅替换末尾 hooks -> hooks.<framework>.ts
entries: [{ find: /hooks$/, replacement: `hooks.${framework}.ts` }],
})
}
🤖 Prompt for AI Agents
In packages/taro-components-react/rollup.config.mjs around lines 187 to 190, the
alias replacement currently uses a function which has compatibility and typing
risks; replace it with a direct regular-expression based replacement (e.g., use
a pattern with a capture group or an end-of-string anchor and a string
replacement like replacement: 'hooks.<framework>.ts' or a regex replacement that
inserts the framework via template interpolation at build time) so the alias
entries use a plain string or regex-replacement instead of a function to avoid
runtime/type issues.

}

Expand All @@ -52,7 +200,7 @@ const base = {
preserveModules: true,
preserveModulesRoot: 'src',
sourcemap: true,
}
},
}

const babelConfig = {
Expand All @@ -63,93 +211,96 @@ const babelConfig = {
const react = () => {
const config = recursiveMerge({}, base, {
input: {
index: 'src/index.react.ts'
index: 'src/index.react.ts',
},
plugins: getPlugins(
[
getAliasPlugin('react'),
],
[getAliasPlugin('react')],
[
babel({
...babelConfig,
presets: [
['@babel/preset-react', {
pure: true,
runtime: 'automatic',
useSpread: true,
}],
[
'@babel/preset-react',
{
pure: true,
runtime: 'automatic',
useSpread: true,
},
],
],
}),
replace({
preventAssignment: true,
'process.env.FRAMEWORK': JSON.stringify('react'),
})
}),
]
)
),
})
return config
}

const solid = () => {
const config = recursiveMerge({}, base, {
input: {
index: 'src/index.solid.ts'
index: 'src/index.solid.ts',
},
output: {
dir: 'dist/solid',
},
plugins: getPlugins(
[
getAliasPlugin('solid')
],
[getAliasPlugin('solid')],
[
babel({
...babelConfig,
presets: [
'babel-preset-solid',
],
presets: ['babel-preset-solid'],
}),
replace({
preventAssignment: true,
'process.env.FRAMEWORK': JSON.stringify('solid'),
}),
]
)
),
})
return config
}

// 新增:样式产物配置
const styleBundles = () => {
const inputs = {
picker: 'src/components/picker/style/index.scss',
}

return Object.entries(inputs).map(([name, inputPath]) => ({
const original = () => {
const config = recursiveMerge({}, base, {
input: {
[name]: inputPath
index: 'src/index.react.ts',
},
output: {
dir: 'dist/components',
entryFileNames: `${name}/react-style/style.js`,
format: 'es',
sourcemap: true,
dir: 'dist/original',
// 移除 assetFileNames 配置,因为 original 构建不再生成 CSS 文件
},
plugins: [
postcss({
extract: path.resolve(`dist/components/${name}/react-style/style.css`),
minimize: true,
sourceMap: true,
modules: false,
autoModules: false,
})
]
}))
plugins: getPlugins(
[getAliasPlugin('react')],
[
babel({
...babelConfig,
presets: [
[
'@babel/preset-react',
{
pure: true,
runtime: 'automatic',
useSpread: true,
},
],
],
}),
replace({
preventAssignment: true,
'process.env.FRAMEWORK': JSON.stringify('react'),
}),
mergeScssFiles(), // 合并 SCSS 文件到输出目录
fixStyleImports(), // 修复样式 import 语句,保持 SCSS 引用
],
true // 标记为 original 模式
),
})
return config
}

// 供 Loader 使用的运行时入口
export default defineConfig([
react(),
solid(),
...styleBundles() // 新增的样式产物
])
export default defineConfig([react(), solid(), original()])
Loading
Loading