Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 将taro-plugin-solid与taro-plugin-react分离 #15595

Merged
merged 64 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
8305025
fix(solid): 删除h函数
phy-lei Apr 12, 2024
8cb9ce1
feat: add babel-plugin-transform-solid-jsx-ad-taro-components
phy-lei Apr 14, 2024
bee5785
feat: 完成babel的solid插件,在小程序端准确编译taroComponent
phy-lei Apr 14, 2024
0122b5b
chore(babel-solid): 入口文件修改为适配babel的入口
phy-lei Apr 14, 2024
7e409bf
feat(babel-solid): 解耦getTagName
phy-lei Apr 14, 2024
de4b178
fix(solid-babel): 修复solid中对于@tarojs/components的无引用import,收集不到小程序组件bug
phy-lei Apr 15, 2024
54c32be
feat(babel-solid): 修改项目的readme及license
phy-lei Apr 15, 2024
176d4ef
feat(babel-solid): 插件添加h5判断,h5不进行组件转换
phy-lei Apr 15, 2024
e628bff
chore: 修改打包文件路径
phy-lei Apr 15, 2024
5e36a0f
feat(babel-solid): 添加测试用例
phy-lei Apr 15, 2024
c1f6264
chore: eslint ignore babel solid
phy-lei Apr 15, 2024
32fc777
chore: 同步收集小程序组件到其他runner中
phy-lei Apr 15, 2024
da197bf
chore
phy-lei Apr 15, 2024
d3260c8
Merge branch '4.x' of https://github.com/NervJS/taro into fix/solid-r…
phy-lei Apr 15, 2024
2b7c69d
feat: add stencil-solid-output-target
phy-lei Apr 13, 2024
39543bd
chore
phy-lei Apr 16, 2024
13c8f94
feat: 自定义solid-stencil-output
phy-lei Apr 16, 2024
499cd10
feat: 初步完成stencil的solid打包
phy-lei Apr 16, 2024
56fdb46
fix(h5-solid): 顺利编译taro的component,但响应式丢失
phy-lei Apr 16, 2024
04d6142
chore: 调整stencil-solid的createComponent
phy-lei Apr 17, 2024
da112af
fix(h5-solid): 修复web-component的solid连接器编译错乱
phy-lei Apr 18, 2024
946a1de
fix(h5-solid): 完善stencil-solid的连接器,解决props响应式丢失
phy-lei Apr 18, 2024
cc132ba
feat: 优化solid-createComponent代码
phy-lei Apr 19, 2024
9504f30
Merge branch '4.x' of https://github.com/NervJS/taro into fix/solid-r…
phy-lei Apr 19, 2024
5f11ae0
Merge branch 'fix/solid-reactive' of github.com:phy-lei/taro into fix…
phy-lei Apr 19, 2024
55014aa
chore
phy-lei Apr 19, 2024
8b2645d
fix: 修复classList失效的bug
phy-lei Apr 19, 2024
4e19050
feat: 响应式props及element event不通过props绑定,会造成el多余props显示,采用setAttribute及…
phy-lei Apr 19, 2024
354a9f2
chore
phy-lei Apr 19, 2024
c76aa9f
chore: stencil的component同步solid对dom的api调用
phy-lei Apr 24, 2024
52bb6c1
feat: 新增plugin-framework-solid
phy-lei Apr 26, 2024
10f5cc5
feat: taro-plugin-react删除solid相关代码
phy-lei Apr 27, 2024
f8a7ad5
feat: 校准其他模块与taro-react-plugin关联了solid的指向
phy-lei Apr 27, 2024
ec9b1cf
fix: 修复小程序编译及在h5端,不改变solid的reconciler别名为solid-js/web
phy-lei Apr 27, 2024
2fc3207
fix: 跑通h5流程
phy-lei Apr 28, 2024
3f135a8
chore: 修改babel-solid文件命名
phy-lei May 3, 2024
e840c0e
chore: 修改babel-solid相关的工程化配置
phy-lei May 3, 2024
c04ef10
chore: 类型命名修改
phy-lei May 3, 2024
56fbdb2
chore: 类型命名修改
phy-lei May 3, 2024
18f324c
chore: eslintignore采用根目录的
phy-lei May 3, 2024
baba7e9
Merge branches 'fix/solid-reactive-h5' and 'fix/solid-reactive' of gi…
phy-lei May 3, 2024
b7cc39e
Merge branch '4.x' of https://github.com/NervJS/taro into fix/solid-r…
phy-lei May 3, 2024
3b1ae39
Merge branch 'fix/solid-reactive' of github.com:phy-lei/taro into fix…
phy-lei May 3, 2024
7ed1b8e
Merge branch '4.x' of https://github.com/NervJS/taro into feat/taro-p…
phy-lei May 4, 2024
1066762
Merge branch '4.x' of https://github.com/NervJS/taro into fix/solid-r…
phy-lei May 6, 2024
25e68e7
chore: sort packages
phy-lei May 6, 2024
a8432b9
fix: babel-solid的ignore加入,修复eslint暴露的问题
phy-lei May 6, 2024
3b690de
chore
phy-lei May 6, 2024
893bd6e
Merge branch 'fix/solid-reactive' of github.com:phy-lei/taro into fix…
phy-lei May 6, 2024
7ffbbbe
feat: 完成solid在h5的vite编译
phy-lei May 11, 2024
94671cc
chore: 暂时注释babel
phy-lei May 11, 2024
453727a
chore: solid-components打包对于solid-js及tarojs的包使用外部依赖
phy-lei May 13, 2024
08d140d
chore: vite插件顺序改变
phy-lei May 13, 2024
2101c55
chore: 格式化
phy-lei May 13, 2024
a4e11c5
refactor: 修改框架插件目录名称
Jun 3, 2024
0387dd9
Merge branch '4.x' into feat/taro-plugin-solid
Jun 3, 2024
889c051
refactor: 依赖治理 taro-framework-solid
Jun 3, 2024
fd0e698
refactor: 解决合并错误
Jun 3, 2024
455fbb7
Merge branch '4.x' into fix/solid-reactive-h5
Jun 3, 2024
5f50ced
refactor: 依赖治理
Jun 3, 2024
33b539c
refactor: babel-plugin-transform-solid-jsx 测试命令
Jun 3, 2024
34d580c
fix: 解决合并造成的问题
Jun 3, 2024
f63e1ce
Merge branch '4.x' into fix/solid-reactive
Jun 3, 2024
7ef20da
Merge branch 'fix/solid-reactive' into feat/taro-plugin-solid
Jun 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions packages/babel-preset-taro/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ module.exports = (_, options = {}) => {
}
}
} else if (isSolid) {
presets.push([
require('babel-plugin-transform-solid-jsx'),
{
moduleName: '@tarojs/plugin-framework-react/dist/reconciler',
const solidOptions = {}
if (process.env.TARO_PLATFORM !== 'web') {
Object.assign(solidOptions, {
moduleName: '@tarojs/plugin-framework-solid/dist/reconciler',
generate: 'universal',
uniqueTransform: process.env.TARO_PLATFORM !== 'web',
},
uniqueTransform: true,
})
}
presets.push([
require('babel-plugin-transform-solid-jsx-ad-taro-components'),
solidOptions,
])
}

Expand Down
3 changes: 2 additions & 1 deletion packages/taro-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const DEFAULT_FRAMEWORK = 'react'

export default class CLI {
appPath: string
constructor (appPath) {
constructor(appPath) {
this.appPath = appPath || process.cwd()
}

Expand Down Expand Up @@ -143,6 +143,7 @@ export default class CLI {
react: '@tarojs/plugin-framework-react',
preact: '@tarojs/plugin-framework-react',
nerv: '@tarojs/plugin-framework-react',
solid: '@tarojs/plugin-framework-solid',
}
if (frameworkMap[framework]) {
kernel.optsPlugins.push(frameworkMap[framework])
Expand Down
32 changes: 10 additions & 22 deletions packages/taro-framework-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { PluginOption } from 'vite'
export type Frameworks = 'react' | 'preact' | 'solid' | 'vue3'

export function isReactLike(framework: IProjectConfig['framework'] = 'react'): framework is Frameworks {
return ['react', 'preact', 'solid'].includes(framework)
return ['react', 'preact'].includes(framework)
}

export default (ctx: IPluginContext) => {
Expand Down Expand Up @@ -63,7 +63,7 @@ export default (ctx: IPluginContext) => {

const taroReactPlugin: esbuild.Plugin = {
name: 'taroReactPlugin',
setup(build) {
setup (build) {
build.onLoad({ filter: REG_TARO_H5 }, ({ path }) => {
const content = fs.readFileSync(path).toString()
return {
Expand Down Expand Up @@ -95,19 +95,13 @@ export default (ctx: IPluginContext) => {
})
}

function setAlias(framework: Frameworks, chain) {
function setAlias (framework: Frameworks, chain) {
const alias = chain.resolve.alias

switch (framework) {
case 'preact':
alias.set('react', 'preact/compat')
alias.set('react-dom/test-utils', 'preact/test-utils')
alias.set('react-dom', 'preact/compat')
alias.set('react/jsx-runtime', 'preact/jsx-runtime')
break
case 'solid':
alias.set('react/jsx-runtime', 'solid-js/h/jsx-runtime')
break
if (framework === 'preact') {
alias.set('react', 'preact/compat')
alias.set('react-dom/test-utils', 'preact/test-utils')
alias.set('react-dom', 'preact/compat')
alias.set('react/jsx-runtime', 'preact/jsx-runtime')
}
}

Expand All @@ -131,10 +125,10 @@ function VitePresetPlugin (framework: Frameworks): PluginOption {
})
}

function viteCommonPlugin(framework: Frameworks): PluginOption {
function viteCommonPlugin (framework: Frameworks): PluginOption {
return {
name: 'taro-react:common',
config() {
config () {
const alias =
framework === 'preact'
? [
Expand All @@ -144,12 +138,6 @@ function viteCommonPlugin(framework: Frameworks): PluginOption {
{ find: 'react/jsx-runtime', replacement: 'preact/jsx-runtime' },
]
: []
if (framework === 'solid') {
const reconcilerName = '@tarojs/plugin-framework-react/dist/reconciler'
alias.push(
{ find: 'react/jsx-runtime', replacement: reconcilerName },
)
}

return {
resolve: {
Expand Down
14 changes: 0 additions & 14 deletions packages/taro-framework-react/src/loader-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,6 @@ class App extends React.Component {
}
}

if (framework === 'solid') {
Object.assign(loaderMeta, {
creator: 'createSolidApp',
frameworkArgs: 'config',
importFrameworkStatement: '',
importFrameworkName: '',
mockAppStatement: `
function App(props) {
return null
}
`,
})
}

if (process.env.TARO_PLATFORM === 'web') {
if (framework === 'react') {
const react = require('react')
Expand Down
3 changes: 1 addition & 2 deletions packages/taro-framework-react/src/runtime/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ export function setReconciler (ReactDOM?) {
})
})

// TODO 使用 solid 时,暂不支持以下事件
if (process.env.TARO_PLATFORM === 'web' && process.env.FRAMEWORK !== 'solid') {
if (process.env.TARO_PLATFORM === 'web') {
hooks.tap('createPullDownComponent', (
el: React.FunctionComponent<PageProps> | React.ComponentClass<PageProps>,
_,
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-framework-react/src/vite.h5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function esbuildExclude (framework: Frameworks): PluginOption {
enforce: 'pre',
config: () => ({
optimizeDeps: {
exclude: ['react', 'preact', 'solid-js']
exclude: ['react', 'preact']
}
})
}
Expand Down
17 changes: 0 additions & 17 deletions packages/taro-framework-react/src/vite.harmony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,6 @@ function aliasPlugin (ctx: IPluginContext, framework: Frameworks): PluginOption
}
}

return {
resolve: {
alias
}
}
}
}
} else if (framework === 'solid') {
return {
name: 'taro-solid:alias',
config () {
const reconcilerName = '@tarojs/plugin-framework-react/dist/reconciler'
const alias = [
{ find: 'solid-js/web', replacement: reconcilerName },
{ find: 'react/jsx-runtime', replacement: reconcilerName },
]

return {
resolve: {
alias
Expand Down
17 changes: 0 additions & 17 deletions packages/taro-framework-react/src/vite.mini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,6 @@ function aliasPlugin (ctx: IPluginContext, framework: Frameworks): PluginOption
}
}

return {
resolve: {
alias
}
}
}
}
} else if (framework === 'solid') {
return {
name: 'taro-solid:alias',
config () {
const reconcilerName = '@tarojs/plugin-framework-react/dist/reconciler'
const alias = [
{ find: 'solid-js/web', replacement: reconcilerName },
{ find: 'react/jsx-runtime', replacement: reconcilerName },
]

return {
resolve: {
alias
Expand Down
14 changes: 4 additions & 10 deletions packages/taro-framework-react/src/webpack.h5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export function modifyH5WebpackChain (ctx: IPluginContext, framework: Frameworks
})
}

function setLoader(framework: Frameworks, chain) {
function customizer(object = '', sources = '') {
function setLoader (framework: Frameworks, chain) {
function customizer (object = '', sources = '') {
if ([object, sources].every((e) => typeof e === 'string')) return object + sources
}
chain.plugin('mainPlugin').tap((args) => {
Expand All @@ -59,7 +59,7 @@ function setLoader(framework: Frameworks, chain) {
})
}

function setPlugin(ctx: IPluginContext, framework: Frameworks, chain) {
function setPlugin (ctx: IPluginContext, framework: Frameworks, chain) {
const config = ctx.initialConfig
const webpackConfig = chain.toConfig()
const isProd = webpackConfig.mode === 'production'
Expand All @@ -78,13 +78,7 @@ function setPlugin(ctx: IPluginContext, framework: Frameworks, chain) {
basedir: process.cwd(),
mainFields,
}
if (framework === 'solid') {
const reconcilerName = '@tarojs/plugin-framework-react/dist/reconciler'
const alias = chain.resolve.alias
alias.set(reconcilerName, resolveSync('solid-js/web', resolveOptions))
// Note: 本地 link 调试时,避免 solid 重复打包
alias.set('solid-js$', resolveSync('solid-js', resolveOptions))
} else if (framework === 'react') {
if (framework === 'react') {
const alias = chain.resolve.alias
// Note: 本地 link 调试时,避免 react 重复打包
alias.set('react$', resolveSync('react', resolveOptions))
Expand Down
4 changes: 0 additions & 4 deletions packages/taro-framework-react/src/webpack.harmony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ function setAlias (ctx: IPluginContext, framework: Frameworks, chain) {
}
}
}
} else if (framework === 'solid') {
const reconcilerName = '@tarojs/plugin-framework-react/dist/reconciler'
alias.set('solid-js/web', reconcilerName)
alias.set('react/jsx-runtime', reconcilerName)
}
}

Expand Down
5 changes: 0 additions & 5 deletions packages/taro-framework-react/src/webpack.mini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ function setAlias (ctx: IPluginContext, framework: Frameworks, chain) {
}
}
}
} else if (framework === 'solid') {
const reconcilerName = '@tarojs/plugin-framework-react/dist/reconciler'
alias.set('solid-js/web', reconcilerName)
// Note: 本地 link 调试时,避免 solid 重复打包
alias.set('solid-js$', resolveSync('solid-js', resolveOptions))
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/taro-framework-solid/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `@tarojs/plugin-platform-react`
# `@tarojs/plugin-platform-solid`

Taro 插件。用于支持编译 React/PReact/Nerv
Taro 插件。用于支持编译solid
2 changes: 1 addition & 1 deletion packages/taro-framework-solid/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
declare module '@tarojs/plugin-framework-react/dist/reconciler'
declare module '@tarojs/plugin-framework-solid/dist/reconciler'
49 changes: 24 additions & 25 deletions packages/taro-framework-solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@tarojs/plugin-framework-solid",
"version": "4.0.0-beta.83",
"description": "Solid 框架插件",
"author": "O2Team",
"author": "drchan",
"homepage": "https://github.com/nervjs/taro",
"license": "MIT",
"main": "index.js",
Expand All @@ -19,7 +19,6 @@
"url": "git+https://github.com/NervJS/taro.git"
},
"scripts": {
"prod": "pnpm run build",
"prebuild": "run-s clean",
"build": "pnpm run rollup --environment NODE_ENV:production",
"clean": "rimraf --impl=move-remove dist",
Expand All @@ -29,43 +28,43 @@
"bugs": {
"url": "https://github.com/NervJS/taro/issues"
},
"engines": {
"node": ">= 18"
},
"dependencies": {
"acorn": "^8.11.3",
"acorn-walk": "^8.3.2",
"lodash": "^4.17.21",
"tslib": "^2.6.2"
"@tarojs/helper": "workspace:*",
"@tarojs/service": "workspace:*",
"acorn": "^8.0.4",
"acorn-walk": "^8.0.0",
"lodash": "^4.17.21"
},
"devDependencies": {
"@tarojs/helper": "workspace:*",
"@babel/core": "^7.14.5",
"@tarojs/runtime": "workspace:*",
"@tarojs/shared": "workspace:*",
"@tarojs/service": "workspace:*",
"@tarojs/taro": "workspace:*",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"solid-js": "^1.8.17",
"@tarojs/shared": "workspace:*",
"webpack-chain": "^6.5.1",
"esbuild": "~0.19.5",
"solid-js": "^1.8.16",
"typescript": "^5.3.3",
"vite": "^4.2.0",
"webpack-chain": "^6.5.1"
"vite-plugin-solid": "^2.10.2"
},
"peerDependencies": {
"@tarojs/helper": "workspace:*",
"@tarojs/runtime": "workspace:*",
"@tarojs/shared": "workspace:*",
"solid-js": "^1.8.0",
"vite": "^4",
"webpack": "^5"
"@tarojs/runtime": "workspace:~",
"@tarojs/shared": "workspace:~",
"vite-plugin-solid": "^2",
"webpack": "^5",
"solid-js": ">=1"
},
"peerDependenciesMeta": {
"solid-js": {
"vite-plugin-solid": {
"optional": true
},
"vite": {
"webpack": {
"optional": true
},
"webpack": {
"solid-js": {
"optional": true
},
"vite": {
"optional": true
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/taro-framework-solid/rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import typescript from '@rollup/plugin-typescript'
import ts from '@rollup/plugin-typescript'
import { defineConfig } from 'rollup'
import externals from 'rollup-plugin-node-externals'

Expand All @@ -17,7 +17,7 @@ const base: RollupOptions = {
devDeps: false,
include: [/@tarojs/]
}),
typescript(),
ts(),
]
}

Expand Down Expand Up @@ -45,7 +45,7 @@ const runtimeConfig: RollupOptions = {
}

const reconcilerConfig: RollupOptions = {
input: path.join(cwd, 'src/runtime/reconciler/index.ts'),
input: path.join(cwd, 'src/reconciler/index.ts'),
output: {
file: path.join(cwd, 'dist/reconciler.js'),
format: 'es',
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-framework-solid/src/api-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function (str: string) {
useScope,
useUnhandledRejection,
useUnload
} from '@tarojs/plugin-framework-react/dist/runtime'
} from '@tarojs/plugin-framework-solid/dist/runtime'
${str}

taro.useAddToFavorites = useAddToFavorites
Expand Down
1 change: 1 addition & 0 deletions packages/taro-framework-solid/src/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const RECONCILER_NAME = '@tarojs/plugin-framework-solid/dist/reconciler'