智能小程序开发插件合集

插件

ray 编译插件

// ray.config.ts
import { RayConfig } from '@ray-js/types';
 
// 插件本质上是一个object对象,具体配置查看RayConfig typescript类型
const config: RayConfig = {
  plugins: [
    // 可以是文件,导出插件对象
    require.resolve('./plugin'),
 
    // 可以是函数
    () => {
      return {
        name: 'aaaa',
        configWebpack({ config }) {},
      };
    },
    // 可以是对象
    {
      name: 'plugin name',
    },
  ],
};
export default config;

ray 运行时插件

// ray.config.ts
import { RayConfig } from '@ray-js/types';
 
// 插件本质上是一个object对象,具体配置查看RayConfig typescript类型
const config: RayConfig = {
  plugins: [
    {
      // 运行时插件只能是函数,返回运行时模块的绝对路径
      registerRuntimePlugin() {
        return require.resolve('./runtime');
      },
    },
  ],
};
export default config;

微信小程序插件

// src/routes.config.ts
import { PluginOfMini, SubPackages } from '@ray-js/types';
 
export const plugins: PluginOfMini = {
  'hello-plugin22': {
    version: 'dev',
    provider: 'wxf1eb515130875231',
  },
};
 
export const subPackages: SubPackages = [
  {
    root: 'packageA',
    pages: [
      {
        route: '/a/:uid',
        path: '/pages/a/index',
      },
      {
        route: '/b',
        path: '/pages/b/index',
      },
    ],
    // 子包中的插件
    plugins: {
      // 子包和主包插件的provider不能一样
      'hello-plugin22': {
        version: 'dev',
        provider: 'wxf1eb515130875231',
      },
    },
  },
];
 
// 使用
import { requirePlugin, requirePluginComponent } from 'ray/macro';
 
// 插件暴露的接口
const pluginApi = requirePlugin('hello-plugin22');
pluginApi.xxx();
 
//插件暴露的组件
const PluginComponent = requirePluginComponent('hello-plugin22/component');
 
const Demo = () => {
  return (
    <View>
      <PluginComponent />
    </View>
  );
};

微信小程序子包及其插件

// src/routes.config.ts
import { router } from 'ray';
import { SubPackages, Routes } from '@ray-js/types';
 
export const routes: Routes = [
  {
    route: '/home',
    path: '/pages/index',
  },
];
export const subPackages: SubPackages = [
  {
    root: 'packageA',
    pages: [
      {
        route: '/b',
        path: '/pages/b/index',
      },
    ],
  },
];
 
// src/pages/index
const Demo = () => {
  return (
    <View>
      <View onClick={() => router.push('/b', { subpackage: 'packageA' })}>
        子包页面跳转
      </View>
      <View onClick={() => router.push('/home')}>主包页面跳转</View>
    </View>
  );
};

👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IoT砖家涂拉拉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值