npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@expo-harmony/metro-config

v57.0.13-harmony.1

Published

[**GitHub 仓库**](https://github.com/renbaoshuo/expo-harmony/tree/master/packages/metro-config) | [Expo Metro 配置文档](https://docs.expo.dev/guides/customizing-metro/)

Readme

@expo-harmony/metro-config

GitHub 仓库 | Expo Metro 配置文档

本包用于在 Expo 项目的 Metro 配置中加入 HarmonyOS 支持。

安装

本包适配 Expo SDK 57。

npm install @expo-harmony/metro-config @expo-harmony/expo-modules-core

配置 Metro

在项目根目录的 metro.config.js 中,将 Expo 默认配置传给 withHarmonyConfig:

const { getDefaultConfig } = require('expo/metro-config');
const { withHarmonyConfig } = require('@expo-harmony/metro-config');

const projectRoot = __dirname;
const config = getDefaultConfig(projectRoot);

module.exports = withHarmonyConfig(config, { projectRoot });

如果同一份 Metro 配置也用于 Android 或 iOS,可以只在 HarmonyOS 构建时启用 HarmonyOS 配置:

const { getDefaultConfig } = require('expo/metro-config');
const { withHarmonyConfig } = require('@expo-harmony/metro-config');

const projectRoot = __dirname;
const isHarmony = process.env.EXPO_METRO_TARGET === 'harmony';
const config = getDefaultConfig(projectRoot);

module.exports = withHarmonyConfig(config, {
  enabled: isHarmony,
  projectRoot,
});

enabled 默认为 true。设为 false 时会原样返回传入的 Metro 配置。通过 expo-harmony start 启动 HarmonyOS 开发服务时,CLI 会设置 EXPO_METRO_TARGET=harmony。

替换 HarmonyOS 模块

如果某个依赖没有适配 HarmonyOS,可以用 aliases 指向适配文件,或用 redirects 替换单个模块。redirects 的目标可以是模块名;设为 false 时,该模块会解析为空模块。emptyModules 则可以按模块名、正则表达式或函数匹配需要留空的模块。

这些规则只影响 HarmonyOS bundle,Android 和 iOS 仍使用 Expo 的模块解析配置。

const path = require('node:path');
const { getDefaultConfig } = require('expo/metro-config');
const { withHarmonyConfig } = require('@expo-harmony/metro-config');

const projectRoot = __dirname;
const config = getDefaultConfig(projectRoot);

module.exports = withHarmonyConfig(config, {
  projectRoot,
  aliases: {
    'my-library': path.resolve(projectRoot, 'src/harmony/my-library'),
  },
  redirects: {
    'legacy-module': 'my-library',
    'unsupported-module': false,
  },
  emptyModules: [/MaterialSymbols/u],
});

需要根据导入来源选择不同模块时,可以使用 resolveRequest。例如,下面的配置会在 screens 目录中的文件导入 my-library 时,改为解析 HarmonyOS 入口:

const path = require('node:path');
const { getDefaultConfig } = require('expo/metro-config');
const { withHarmonyConfig } = require('@expo-harmony/metro-config');

const projectRoot = __dirname;
const config = getDefaultConfig(projectRoot);

module.exports = withHarmonyConfig(config, {
  projectRoot,
  resolveRequest({ context, moduleName, resolve }) {
    const screensPath = `${path.sep}screens${path.sep}`;
    if (moduleName === 'my-library' && context.originModulePath.includes(screensPath)) {
      return resolve('my-library/harmony');
    }
    return null;
  },
});

返回 null 或 undefined 时,会继续使用其他 HarmonyOS 模块解析规则。resolve 可以调用 Expo 的默认解析过程;需要跳过自定义规则并直接解析 HarmonyOS 模块时,可以使用 resolveHarmony。

配置项按 emptyModules、resolveRequest、redirects、aliases 的顺序处理,未匹配的模块会交给 HarmonyOS 模块解析器继续查找。aliases 支持模块名前缀,多个别名都匹配时会使用最长前缀。

调整 HarmonyOS 模块解析

conditions 用于补充 HarmonyOS 的 package exports 条件,默认包含 harmony 和 react-native。如果项目使用其他 React Native HarmonyOS 包,可以通过 reactNativeHarmonyPackageName 指定包名;该包提供额外 Metro 选项时,可以放在 harmonyConfigOptions 中:

const { getDefaultConfig } = require('expo/metro-config');
const { withHarmonyConfig } = require('@expo-harmony/metro-config');

const config = getDefaultConfig(__dirname);

module.exports = withHarmonyConfig(config, {
  conditions: ['harmony', 'react-native'],
  reactNativeHarmonyPackageName: '@react-native-oh/react-native-harmony',
  harmonyConfigOptions: {
    // 填写所用 React Native HarmonyOS 包支持的 Metro 选项。
  },
});

与其他 Metro 配置组合

如果项目还使用 NativeWind 等 Metro 配置增强器,先将 Expo 默认配置传给 withHarmonyConfig,再将结果传给其他增强器:

const { getDefaultConfig } = require('expo/metro-config');
const { withHarmonyConfig } = require('@expo-harmony/metro-config');
const { withNativeWind } = require('nativewind/metro');

const config = withHarmonyConfig(getDefaultConfig(__dirname));
module.exports = withNativeWind(config, { input: './global.css' });

Author

expo-harmony © Baoshuo, Released under the MIT License. Authored and maintained by Baoshuo with help from contributors.

Personal Website · Blog · GitHub @renbaoshuo · Twitter @renbaoshuo