Skip to content

Commit

Permalink
fix(h5): trans webpackMode weak 2 lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Jun 5, 2023
1 parent 1efca7c commit 05a5207
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 25 deletions.
5 changes: 1 addition & 4 deletions packages/taro-components/src/components/image/image.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Component, Prop, h, ComponentInterface, Host, State, Event, EventEmitter } from '@stencil/core'
import classNames from 'classnames'

import(
/* webpackMode: "weak" */
'intersection-observer'
)
import('intersection-observer')

export type Mode =
'scaleToFill'
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-components/src/components/video/video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export class Video implements ComponentInterface {

if (isHls(src)) {
import(
/* webpackMode: "weak" */
/* webpackExports: ["default"] */
'hls.js'
).then(e => {
const Hls = e.default
Expand Down
6 changes: 3 additions & 3 deletions packages/taro-h5/src/api/media/image/chooseImage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Taro from '@tarojs/api'

import { shouldBeObject } from '../../../utils'
import { chooseMedia } from '../video'
import { chooseMedia } from '../video/chooseMedia'

/**
* 从本地相册选择图片或使用相机拍照。
Expand All @@ -11,7 +11,7 @@ export const chooseImage: typeof Taro.chooseImage = function (options) {
// options must be an Object
const isObject = shouldBeObject(options)
if (!isObject.flag) {
const res = { errMsg: `${chooseImage.name}:fail ${isObject.msg}` }
const res = { errMsg: `chooseImage:fail ${isObject.msg}` }
console.error(res.errMsg)
return Promise.reject(res)
}
Expand Down Expand Up @@ -57,5 +57,5 @@ export const chooseImage: typeof Taro.chooseImage = function (options) {
fail?.(err)
complete?.(err)
},
}, chooseImage.name).then(parseRes)
}, 'chooseImage').then(parseRes)
}
2 changes: 1 addition & 1 deletion packages/taro-h5/src/api/media/video/chooseMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { MethodHandler } from '../../../utils/handler'
*/
export const chooseMedia = async function (
options: Taro.chooseMedia.Option,
methodName = chooseMedia.name,
methodName = 'chooseMedia',
): Promise<Taro.chooseMedia.SuccessCallbackResult> {
// options must be an Object
const isObject = shouldBeObject(options)
Expand Down
4 changes: 2 additions & 2 deletions packages/taro-h5/src/api/media/video/chooseVideo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const chooseVideo: typeof Taro.chooseVideo = (options) => {
// options must be an Object
const isObject = shouldBeObject(options)
if (!isObject.flag) {
const res = { errMsg: `${chooseVideo.name}:fail ${isObject.msg}` }
const res = { errMsg: `chooseVideo:fail ${isObject.msg}` }
console.error(res.errMsg)
return Promise.reject(res)
}
Expand Down Expand Up @@ -48,5 +48,5 @@ export const chooseVideo: typeof Taro.chooseVideo = (options) => {
fail?.(err)
complete?.(err)
},
}, chooseVideo.name).then(parseRes)
}, 'chooseVideo').then(parseRes)
}
8 changes: 4 additions & 4 deletions packages/taro-h5/src/api/media/video/getVideoInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const getVideoInfo: typeof Taro.getVideoInfo = async function (options) {
// options must be an Object
const isObject = shouldBeObject(options)
if (!isObject.flag) {
const res = { errMsg: `${getVideoInfo.name}:fail ${isObject.msg}` }
const res = { errMsg: `getVideoInfo:fail ${isObject.msg}` }
console.error(res.errMsg)
return Promise.reject(res)
}
Expand All @@ -29,7 +29,7 @@ export const getVideoInfo: typeof Taro.getVideoInfo = async function (options) {
fail,
complete,
} = options
const handle = new MethodHandler({ name: getVideoInfo.name, success, fail, complete })
const handle = new MethodHandler({ name: 'getVideoInfo', success, fail, complete })

if (typeof src !== 'string') {
res.errMsg = getParameterError({
Expand All @@ -50,14 +50,14 @@ export const getVideoInfo: typeof Taro.getVideoInfo = async function (options) {
res.duration = video.duration
res.height = video.videoHeight
res.width = video.videoWidth

fetch(src)
.then(async e => {
const blob = await e.blob()
res.type = blob.type
res.size = blob.size
res.bitrate = blob.size / video.duration

handle.success(res, { resolve, reject })
})
.catch(e => {
Expand Down
12 changes: 6 additions & 6 deletions packages/taro-h5/src/api/ui/interaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const showToast: typeof Taro.showToast = (options = { title: '' }) => {
mask: false
}, options)
const { success, fail, complete } = options
const handle = new MethodHandler({ name: showToast.name, success, fail, complete })
const handle = new MethodHandler({ name: 'showToast', success, fail, complete })

if (typeof options.title !== 'string') {
return handle.fail({
Expand Down Expand Up @@ -72,7 +72,7 @@ const showToast: typeof Taro.showToast = (options = { title: '' }) => {
}

const hideToast: typeof Taro.hideToast = ({ noConflict = false, success, fail, complete } = {}) => {
const handle = new MethodHandler({ name: hideToast.name, success, fail, complete })
const handle = new MethodHandler({ name: 'hideToast', success, fail, complete })
if (!toast.el) return handle.success()
toast.hide(0, noConflict ? 'toast' : '')
return handle.success()
Expand All @@ -85,7 +85,7 @@ const showLoading: typeof Taro.showLoading = (options = { title: '' }) => {
mask: false
}, options)
const { success, fail, complete } = options
const handle = new MethodHandler({ name: showLoading.name, success, fail, complete })
const handle = new MethodHandler({ name: 'showLoading', success, fail, complete })

const config = {
icon: 'loading',
Expand Down Expand Up @@ -117,7 +117,7 @@ const showLoading: typeof Taro.showLoading = (options = { title: '' }) => {
}

const hideLoading: typeof Taro.hideLoading = ({ noConflict = false, success, fail, complete } = {}) => {
const handle = new MethodHandler({ name: hideLoading.name, success, fail, complete })
const handle = new MethodHandler({ name: 'hideLoading', success, fail, complete })
if (!toast.el) return handle.success()
toast.hide(0, noConflict ? 'loading' : '')
return handle.success()
Expand All @@ -135,7 +135,7 @@ const showModal: typeof Taro.showModal = async (options = {}) => {
confirmColor: '#3CC51F'
}, options)
const { success, fail, complete } = options
const handle = new MethodHandler({ name: showModal.name, success, fail, complete })
const handle = new MethodHandler({ name: 'showModal', success, fail, complete })

if (typeof options.title !== 'string') {
return handle.fail({
Expand Down Expand Up @@ -229,7 +229,7 @@ function hideModal () {

const showActionSheet = async (
options: Taro.showActionSheet.Option = { itemList: [] },
methodName = showActionSheet.name
methodName = 'showActionSheet'
): Promise<Taro.showActionSheet.SuccessCallbackResult> => {
init(document)
options = Object.assign({
Expand Down
5 changes: 1 addition & 4 deletions packages/taro-h5/src/api/wxml/IntersectionObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import Taro from '@tarojs/api'

import { findDOM } from '../../utils'

import(
/* webpackMode: "weak" */
'intersection-observer'
)
import('intersection-observer')

type TElement = Document | HTMLElement | Element

Expand Down

0 comments on commit 05a5207

Please sign in to comment.