Skip to content

Commit

Permalink
fix(components): 组件库各框架适配层先走 babel 编译, fix #6758
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen-jj committed Jun 28, 2020
1 parent bc434e5 commit 05fe46d
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 27 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-decorators": "^7.6.0",
"@babel/plugin-proposal-do-expressions": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.6.2",
"@babel/plugin-proposal-object-rest-spread": "^7.10.3",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-transform-react-jsx": "^7.3.0",
"@babel/plugin-transform-runtime": "^7.10.3",
"@babel/preset-env": "^7.6.2",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.6.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/taro-components/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ src/demo

# build
dist
dist-h5
build

# jest
coverage
__snapshots__
.stencil
loader
loader
3 changes: 2 additions & 1 deletion packages/taro-components/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
],
plugins: [
'@babel/plugin-proposal-class-properties'
]
],
babelrcRoots: ['./h5/*']
}
16 changes: 16 additions & 0 deletions packages/taro-components/h5/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
presets: [
['@babel/env', {
targets: {
ios: '9',
android: '5'
},
modules: false
}]
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-transform-runtime'
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<script>
import { listeners } from '../mixins/listeners'
import { refs } from '../mixins/refs'
export default {
Expand All @@ -10,12 +9,11 @@ export default {
render (createElement) {
const iconType = this.type.replace(/_/g, '-')
return createElement('taro-icon-core', {
'class': ['hydrated', `weui-icon-${iconType}`],
class: ['hydrated', `weui-icon-${iconType}`],
attrs: {
type: this.type
},
'on': this.listeners
on: this.listeners
}, this.$slots.default)
}
}
</script>
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<script>
import { listeners } from '../mixins/listeners'
import { refs } from '../mixins/refs'
export default {
Expand All @@ -9,14 +8,13 @@ export default {
},
render (createElement) {
return createElement('taro-image-core', {
'class': ['hydrated', {
class: ['hydrated', {
'taro-img__widthfix': this.mode === 'widthFix'
}],
attrs: {
mode: this.mode
},
'on': this.listeners
on: this.listeners
}, this.$slots.default)
}
}
</script>
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<script>
import { listeners } from '../mixins/listeners'
import { refs } from '../mixins/refs'
export default {
Expand All @@ -20,6 +19,7 @@ export default {
}
},
render (createElement) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this

return createElement('taro-picker-core', {
Expand All @@ -37,4 +37,3 @@ export default {
}, self.$slots.default)
}
}
</script>
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<script>
import { listeners } from '../mixins/listeners'
import { refs } from '../mixins/refs'
export default {
Expand All @@ -9,6 +8,7 @@ export default {
scrollY: Boolean
},
render (createElement) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this

const attrs = {}
Expand All @@ -32,4 +32,3 @@ export default {
}, self.$slots.default)
}
}
</script>
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<script>
import { listeners } from '../mixins/listeners'
import { refs } from '../mixins/refs'
export default {
Expand All @@ -9,14 +8,13 @@ export default {
},
render (createElement) {
return createElement('taro-text-core', {
'class': ['hydrated taro-text', {
class: ['hydrated taro-text', {
'taro-text__selectable': this.selectable
}],
attrs: {
selectable: this.selectable
},
'on': this.listeners
on: this.listeners
}, this.$slots.default)
}
}
</script>
10 changes: 5 additions & 5 deletions packages/taro-components/h5/vue/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Vue from 'vue'
import createComponent from './createComponent'
import createFormsComponent from './createFormsComponent'
import Picker from './components/picker.vue'
import Text from './components/text.vue'
import Image from './components/image.vue'
import Icon from './components/icon.vue'
import ScrollView from './components/scroll-view.vue'
import Picker from './components/picker'
import Text from './components/text'
import Image from './components/image'
import Icon from './components/icon'
import ScrollView from './components/scroll-view'

import { simpleComponents } from './simpleComponents'

Expand Down
4 changes: 3 additions & 1 deletion packages/taro-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"collection": "dist/collection/collection-manifest.json",
"collection:main": "dist/collection/index.js",
"scripts": {
"build": "stencil build --config stencil.config.ts",
"build-h5": "babel -d dist-h5 h5",
"build": "npm run build-h5 & stencil build --config stencil.config.ts",
"dev": "stencil build --config stencil.config.ts --watch",
"test": "karmatic --files '__tests__/**.spec.js' --coverage false",
"test:ci": "karmatic --files '__tests__/**.spec.js' --coverage false",
Expand All @@ -47,6 +48,7 @@
"weui": "^1.1.2"
},
"devDependencies": {
"@babel/cli": "^7.10.3",
"@stencil/sass": "^1.1.1",
"jquery": "^3.4.1",
"simulant": "^0.2.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-loader/src/h5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var tabbarSelectedIconPath = []
})
`
const vue = `
import '@tarojs/components/h5/vue'
import '@tarojs/components/dist-h5/vue'
`

const code = `import { createRouter } from '@tarojs/taro'
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-webpack-runner/src/config/dev.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default function (appPath: string, config: Partial<BuildConfig>): any {

const mode = 'development'

alias['@tarojs/components$'] = `@tarojs/components/h5/${config.framework === 'vue' ? 'vue' : 'react'}`
alias['@tarojs/components$'] = `@tarojs/components/dist-h5/${config.framework === 'vue' ? 'vue' : 'react'}`

if (config.framework === 'vue') {
const VueLoaderPlugin = require('vue-loader/lib/plugin')
Expand Down

0 comments on commit 05fe46d

Please sign in to comment.