1.2.5 • Published 3 years ago

@antmove/wx-wx v1.2.5

Weekly downloads
22
License
GPL-3.0
Repository
-
Last release
3 years ago

wx-compiler-plugin

wx-compiler-plugin,Antmove工具下实现微信小程序输出干净代码的方案。

转换器的编译工作只能尽量的覆盖微信小程序项目代码,但微信小程序平台和支付宝小程序平台还是存在不少的差异化是转换工具难以处理的,比如登录、支付、地图特定 API。基于以上的考虑, antmove 提供了一种支付宝代码与微信小程序代码混合编写的方式来适配双端。wx-compiler方案可使微信小程序项目小程序输出干净代码,不再为重复开发而烦恼。

示例

if (wx.__target__ === 'alipay') {
    // 支付宝小程序代码
    console.log('I am alipay mini-program.');
} else {
    // 微信小程序代码
    console.log('I am wechat mini-program.');
}
微信小程序代码(通过工具转换到微信平台)
console.log('I am wechat mini-program.');
  • 安装
    • VsCode 转换插件
    • VsCode 编译步骤
    • 使用 npm 或 yarn 安装
  • 快速开始
    • 命令行使用
    • 命令行参数说明
    • Node.js 使用方式
  • API
    • transformFramework
    • App
  • 贡献
  • 协议
  • 联系

安装

VsCode 转换插件

在 VsCode 扩展中搜索 Antmove 下载安装 Antmove vscode 转换插件实现一键转换。

VsCode 编译步骤

  • 安装扩展(Antmove - antmove-vscode-plugin)
  • 在 VsCode 中打开要转换的项目
  • 打开 VsCode 命令面板
    • Mac: command + shift + p
    • Windows: ctrl + shift + p
  • 输入 Antmove
  • 运行 Antmove: Run antmove wx-compiler 命令,实现微信小程序转换支付宝小程序的转换
  • 运行如上命令后会给出一个弹窗,选择转换后生成代码存储目录
  • 转换完成

  • antmove-vscode-plugin

本插件依赖于 vscode 代码编辑器,安装了 vscode 的用户才能使用。

使用 npm 或 yarn 安装

我们推荐使用 npm 或 yarn 的方式进行开发,不仅可在开发环境轻松调试,也可放心地在生产环境打包部署使用,享受整个生态圈和工具链带来的诸多好处。

  • 全局安装
$ npm install antmove -g
  • 本地安装
$ npm install antmove --save

如果你的网络环境不佳,推荐使用 cnpm

快速开始

命令行使用

通过 npm 或 yarn 全局安装才能使用如下命令行

提供两种可用的命令行调用方式

  • antmove wx-compiler(使用前请将终端切换到需转换编译的微信小程序项目路径)
antmove wx-compiler ./dist/alipay-app
  • antmove - 该命令更加灵活,可配置输出输出目录/编译模式等
antmove -i ./wechat-mini/project -o ./dist/wechat-mini/project --env development

如上的命令表示将 ./wechat-mini/project 存在混合代码的小程序项目转换为微信小程序项目,转换到 ./dist/weichat-mini/project 目录

命令行参数说明

  • --input,-i
    • 可选,编译源码目录,如果不传则是当前目录
  • --output,-o
    • 必传,编译输出目录
  • --env,-e
    • 可选(development/production),编译模式,生产模式代码会压缩,无编译日志及运行时日志
  • --component,-c
    • 可选,组件维度转换,用来转换小程序的插件或组件
  • --type,-t
    • 可选,(wx-alipay),选择编译工具,此参数代表选择的微信转支付宝的工具

Node.js 使用方式

示例

const path = require('path');
const transformFramework = require('antmove');
const WechatPlugin = require('@antmove/wx-wx');

let outputPath = path.join(__dirname, '../../dist');
let inputDirPath = path.join(__dirname, '../../examples/miniprogram-demo/miniprogram');

const App = transformFramework();

App.use(
    WechatPlugin, 
    {
        entry: inputDirPath,
        dist: outputPath + '/alipaymini-demo',
        env: 'development',
        type: 'wx-wx'
    })
    .start();

API

transformFramework

工具实例生成函数。

const transformFramework = require('antmove');
const App = transformFramework();   // 得到的 app 实例即可进行转换处理操作

App

  • use | Function - App.use(plugin, pluginOptions) - 挂载插件到实例上,可挂载多个,按挂载顺序执行
    • plugin: 转换插件
    • pluginOptions: 转换插件配置项
      • entry | String - 转换源码目录
      • dist | String - 转换后代码输出目录
      • env | String - 编译环境设置(env/prod)
        • 默认值为生产环境
  • start | Function - 开始编译操作

贡献

欢迎参与 Antmove 项目的开发建设和讨论。

提交 pull request 之前请先提 Issue 讨论.

协议

GPL

联系

如果您在使用的过程中碰到问题,可以通过下面几个途径寻求帮助。

  • 钉钉微信交流群:
  • 邮件:amap-appx@service.autonavi.com
1.2.5

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.0

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.0.66

4 years ago

1.0.64

4 years ago

1.0.62

4 years ago

1.0.61

4 years ago

1.0.56

4 years ago

1.0.51

4 years ago

1.0.45

4 years ago

1.0.44

4 years ago

1.0.43

4 years ago

1.0.42

4 years ago

1.0.41

4 years ago

1.0.31

4 years ago

1.0.27

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.16

4 years ago

1.0.8

4 years ago

1.0.6

5 years ago

1.0.3

5 years ago