Skip to content

Commit

Permalink
feat: vue support fragment fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Feb 7, 2023
1 parent ff64cad commit c0aa4e0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/taro-components-library-vue2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"author": "ZakaryCode",
"license": "MIT",
"dependencies": {
"@tarojs/components": "workspace:*"
"@tarojs/components": "workspace:*",
"vue-fragment": "^1.6.0"
},
"devDependencies": {
"@babel/cli": "^7.14.5",
Expand Down
4 changes: 3 additions & 1 deletion packages/taro-components-library-vue2/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const config = {
},
treeshake: false,
plugins: [
externals(),
externals({
exclude: ['vue-fragment']
}),
resolve({
preferBuiltins: false,
mainFields: ['main:h5', 'browser', 'module', 'jsnext:main', 'main']
Expand Down
7 changes: 6 additions & 1 deletion packages/taro-components-library-vue2/scripts/fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ const utilsPath = path.resolve(__dirname, '..', 'src/vue-component-lib/utils.ts'

if (fs.existsSync(componentsPath)) {
const codeBuffer = fs.readFileSync(componentsPath)
const code = codeBuffer.toString().replace(/const\sTaro([A-Za-z]+)\s=/g, 'const $1 =').replace(/const\s([A-Za-z]+)Core\s=/g, 'const $1 =')
let code = codeBuffer.toString().replace(/const\sTaro([A-Za-z]+)\s=/g, 'const $1 =').replace(/const\s([A-Za-z]+)Core\s=/g, 'const $1 =')

if (!code.includes('fragment')) {
const comps = ['block', 'custom-wrapper']
code = code.replace(new RegExp(`taro-(${comps.join('|')})-core`, 'ig'), 'fragment')
}

fs.writeFileSync(componentsPath, code)
}
Expand Down
3 changes: 3 additions & 0 deletions packages/taro-components-library-vue2/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Vue from 'vue'
import { ExtendedVue } from 'vue/types/vue'
import Fragment from 'vue-fragment'

import * as components from './components'

Expand All @@ -8,6 +9,8 @@ export function initVue2Components () {
if (!Vue.config.ignoredElements?.includes(ignoredElements[0])) {
Vue.config.ignoredElements = [...Vue.config.ignoredElements, ...ignoredElements]
}

Vue.use(Fragment.Plugin)
Object.entries(components).forEach(params => {
const [name, definition] = params as [string, ExtendedVue<Vue, unknown, unknown, unknown, Record<string, unknown>>]
if (definition) {
Expand Down
8 changes: 7 additions & 1 deletion packages/taro-components-library-vue3/scripts/fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ const utilsPath = path.resolve(__dirname, '..', 'src/vue-component-lib/utils.ts'

if (fs.existsSync(componentsPath)) {
const codeBuffer = fs.readFileSync(componentsPath)
const code = codeBuffer.toString().replace(/const\sTaro([A-Za-z]+)\s=/g, 'const $1 =').replace(/const\s([A-Za-z]+)Core\s=/g, 'const $1 =')
let code = codeBuffer.toString().replace(/const\sTaro([A-Za-z]+)\s=/g, 'const $1 =').replace(/const\s([A-Za-z]+)Core\s=/g, 'const $1 =')

if (!code.includes('Fragment')) {
const comps = ['Block', 'CustomWrapper']
code = code.replace('/* auto-generated vue proxies */', `/* auto-generated vue proxies */\nimport { defineComponent } from 'vue'`)
code = code.replace(new RegExp(`export const (${comps.join('|')}) = \\/\\*\\@__PURE__\\*\\/ defineContainer[^;]*;`, 'ig'), 'export const $1 = defineComponent((__props, { slots }) => slots.default);')
}

fs.writeFileSync(componentsPath, code)
}
Expand Down
14 changes: 13 additions & 1 deletion pnpm-lock.yaml

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

0 comments on commit c0aa4e0

Please sign in to comment.