diff --git a/README.md b/README.md index d12c9e9..094c014 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ Taro 插件。用于支持编译为快手小程序。 ## 版本要求 +### Taro 4+ + +请使用本插件的 7.0 或以上版本 + ### Taro 3.6.9+ 请使用本插件的 6.0 或以上版本 diff --git a/package.json b/package.json index 66e08fe..e8bb594 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/plugin-platform-kwai", - "version": "6.0.1", + "version": "7.0.0", "description": "快手小程序平台插件", "author": "drchan", "homepage": "https://github.com/NervJS/taro-plugin-platform-kwai", @@ -27,16 +27,16 @@ "url": "https://github.com/NervJS/taro-plugin-platform-kwai/issues" }, "peerDependencies": { - "@tarojs/components": "^3.5.0", - "@tarojs/service": "^3.5.0", - "@tarojs/shared": "^3.5.0" + "@tarojs/components": "^4.0.0", + "@tarojs/service": "^4.0.0", + "@tarojs/shared": "^4.0.0" }, "devDependencies": { - "@tarojs/components": "^3.5.0", - "@tarojs/service": "^3.5.0", - "@tarojs/shared": "^3.5.0", - "rollup": "^2.29.0", - "rollup-plugin-typescript2": "^0.27.3", - "typescript": "^4.0.3" + "@tarojs/components": "^4.0.0", + "@tarojs/service": "^4.0.0", + "@tarojs/shared": "^4.0.0", + "rollup": "v4.35.0", + "rollup-plugin-typescript2": "^0.36.0", + "typescript": "^5.4.5" } -} +} \ No newline at end of file diff --git a/rollup.config.js b/rollup.config.js index 4b7f0a9..aa4465e 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -43,4 +43,15 @@ const runtimeUtilsConfig = { ...base } -module.exports = [comileConfig, runtimeConfig, runtimeUtilsConfig] +// React 下 webpack 会 alias @tarojs/components 为此文件 +const otherConfig = { + input: join(cwd, 'src/components-react.ts'), + output: { + file: join(cwd, 'dist/components-react.js'), + format: 'es', + sourcemap: true + }, + ...base +} + +module.exports = [comileConfig, runtimeConfig, runtimeUtilsConfig,otherConfig] diff --git a/src/components-react.ts b/src/components-react.ts new file mode 100644 index 0000000..16cb4b0 --- /dev/null +++ b/src/components-react.ts @@ -0,0 +1,4 @@ +export * from '@tarojs/components/mini' +export const VideoPlayer = 'video-player' +export const PostNoteButton = 'post-note-button' +export const GroupChatCard = 'group-chat-card' \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 5ce1b1b..79d5c9a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,53 +4,15 @@ import type { IPluginContext } from '@tarojs/service' // 让其它平台插件可以继承此平台 export { Kwai } -let registedModifyPageTemplate = false export default (ctx: IPluginContext) => { ctx.registerPlatform({ name: 'kwai', useConfigName: 'mini', async fn ({ config }) { - !registedModifyPageTemplate && modifyPageTemplate(ctx) const program = new Kwai(ctx, config) await program.start() } }) } -// 和支付宝小程序一样,快手小程序中,如果某个页面依赖了原生小程序组件, -// 那么这个页面不能使用公共模板 base.axml, -// 而需要把公共模板的内容在此页面的模板中复制一份, 。 -function modifyPageTemplate (ctx: IPluginContext) { - registedModifyPageTemplate = true - ctx.modifyBuildAssets(({ assets, miniPlugin }) => { - const pages: string[] = [] - - // 筛选出使用了自定义组件的页面 - miniPlugin.pages.forEach(page => { - const config = miniPlugin.filesConfig[miniPlugin.getConfigFilePath(page.name)].content - if (!page.isNative && config?.hasOwnProperty('usingComponents') && Object.keys(config.usingComponents).length) { - pages.push(page.name) - } - }) - - if (!pages.length) return - - const baseXml = assets['base.ksml'].source() - - pages.forEach(page => { - const templateName = `${page}.ksml` - const assetsItem = assets[templateName] - const src = assetsItem._value ? assetsItem._value.toString() : assetsItem.source() - const templateCaller = src.replace(//, '') - const res = `${templateCaller} -${baseXml}` - - assets[templateName] = { - size: () => res.length, - source: () => res - } - }) - }) -} - diff --git a/src/program.ts b/src/program.ts index 8e2af93..7d783c0 100644 --- a/src/program.ts +++ b/src/program.ts @@ -12,7 +12,8 @@ export default class Kwai extends TaroPlatformBase { templ: '.ksml', style: '.css', config: '.json', - script: '.js' + script: '.js', + xs: '.ks', } template = new Template() diff --git a/src/template.ts b/src/template.ts index 09718f6..829e0eb 100644 --- a/src/template.ts +++ b/src/template.ts @@ -1,11 +1,10 @@ -import { indent, Shortcuts } from '@tarojs/shared' import { RecursiveTemplate } from '@tarojs/shared/dist/template' export class Template extends RecursiveTemplate { flattenViewLevel = 8 flattenCoverViewLevel = 8 flattenTextLevel = 3 - supportXS = false + supportXS = true Adapter = { if: 'ks:if', else: 'ks:else', @@ -17,7 +16,7 @@ export class Template extends RecursiveTemplate { type: 'kwai' } - createMiniComponents (components): any { + createMiniComponents(components): any { const result = super.createMiniComponents(components) delete result['pure-view'] @@ -26,126 +25,7 @@ export class Template extends RecursiveTemplate { return result } - buildFlattenNodeAttributes (nodeName: string): string { - const component = this.miniComponents[nodeName] - - return Object.keys(component) - .map(k => `${k}="${k.startsWith('bind') || k.startsWith('on') || k.startsWith('catch') ? component[k] : `{{${component[k].replace(/i./g, 'item.')}}}`}"`) - .join(' ') + ' id="{{item.uid||item.sid}}" data-sid="{{item.sid}}"' - } - - buildFlattenView = (level = this.flattenViewLevel): string => { - if (level === 0) { - return `