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

fix(plugin-inject): 修复 Vue2 使用 componentsMap 配置时报错的问题,#13299 #14520 #14607

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion packages/taro-plugin-inject/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
},
"dependencies": {
"@tarojs/service": "workspace:*",
"@tarojs/shared": "workspace:*"
"@tarojs/shared": "workspace:*",
"@tarojs/helper": "workspace:*"
},
"devDependencies": {
"rollup": "^2.79.0",
Expand Down
20 changes: 12 additions & 8 deletions packages/taro-plugin-inject/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import { esbuild } from '@tarojs/helper'
import { isArray, isFunction, isObject, isString } from '@tarojs/shared'
import * as path from 'path'

Expand All @@ -20,12 +21,6 @@ export interface IOptions {
export default (ctx: IPluginContext, options: IOptions) => {
const fs = ctx.helper.fs

ctx.modifyWebpackChain(({ chain }) => {
if(options.componentsMap){
chain.optimization.providedExports(false)
}
})

ctx.registerMethod({
name: 'onSetupClose',
fn (platform: TaroPlatformBase) {
Expand All @@ -41,7 +36,7 @@ export default (ctx: IPluginContext, options: IOptions) => {

const template = platform.template
if(!template) return

if (isArray(voidComponents)) {
voidComponents.forEach(el => template.voidElements.add(el))
} else if (isFunction(voidComponents)) {
Expand Down Expand Up @@ -89,10 +84,19 @@ function injectRuntimePath (platform: TaroPlatformBase) {
}

function injectComponentsReact (fs, taroComponentsPath, componentsMap) {
fs.writeFileSync(path.resolve(__dirname, '../dist/components-react.js'), `
const filePath = path.resolve(__dirname, '../dist/components-react.js')
fs.writeFileSync(filePath, `
export * from '${taroComponentsPath}'
${Object.keys(componentsMap).map((key) => `export const ${key} = '${componentsMap[key]}'`).join('\n')}
`)
// 提前使用 esbuild 进行 bundle,避免 Webpack 分析过程中的错误,#13299 #14520
const result = esbuild.buildSync({
entryPoints: [filePath],
bundle: true,
write: false,
format: 'esm',
})
fs.writeFileSync(filePath, result.outputFiles[0].text)
}

function injectComponents (fs, components) {
Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading