This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
内联模块引用
Expo 内联模块的参考。
警告 内联模块是实验性功能,仅在 Expo SDK 56 及更高版本中可用。该 API 可能会发生重大更改。
内联模块允许你在 Expo 项目目录中直接编写原生模块代码(Kotlin 和 Swift),而无需创建单独的 Expo 模块包。Expo 会自动发现这些文件并将它们包含在构建中。
🌐 Inline modules let you write native module code (Kotlin and Swift) directly in your Expo project directory, without creating a separate Expo module package. Expo discovers these files automatically and includes them in the build.
配置
🌐 Configuration
expo.experiments.inlineModules.watchedDirectories
配置内联模块可以创建在哪些目录中。
嵌套目录中的文件也将被使用。例如,如果在应用配置中定义了 watchedDirectories = ["app"],并且在嵌套路径中存在一个模块文件,例如 app/nested/directory/SomeModule.kt,那么 SomeModule 可以在你的应用中使用。
🌐 Files inside nested directories will also be used.
For example, if watchedDirectories = ["app"] is defined in the app config,
and a module file such as app/nested/directory/SomeModule.kt exists in a nested path, then SomeModule can be used in your app.
watchedDirectories 中的一个目录:
🌐 A directory in watchedDirectories:
- 需要位于 TypeScript/JavaScript 项目中。这意味着它在目录树中需要有一个包含 package.json 的上级目录。例如,
"watchedDirectories": ["app", "src/some/directory", pathToOtherProject]可以使用,而"watchedDirectories": ["/", pathToFolderNotInNodeProject]不行。 - 不能是整个项目目录,例如
"./",也不能是它的上级目录(例如../)。 watchedDirectories中不能是另一个目录的子目录。例如,watchedDirectories不能是["app", "app/nested/directory"],你可以直接将watchedDirectories设置为["app"]。- 不能包含像
" ", "(", ")", "$"这样的特殊字符。这意味着你不能在watchedDirectories中有"app/(tabs)",但你可以有"app",并且它仍然应该使用来自"app/(tabs)"目录的本地文件。
expo.experiments.inlineModules.xcodeProjectTargets
配置内联模块文件将添加到哪些 Xcode 目标。如果省略,内联模块只会添加到你应用的主目标。
每个条目都是你在 Xcode 项目中看到的目标名称(以及在 ios/Podfile 的 target 块中看到的名字)。只使用目标名称——即使目标嵌套在 abstract_target 里,也不要包含抽象目标的名字。
🌐 Each entry is the name of a target as it appears in your Xcode project (and in the target blocks of your ios/Podfile). Use the target name only — even when the target is nested inside an abstract_target, do not include the abstract target's name.
警告 更改 应用配置 后,你需要运行
npx expo prebuild才能生效。
命名规范
🌐 Naming convention
内联模块的文件名必须与本地模块名匹配(该名称在整个应用中必须唯一)。 如果你有一个 SimpleModule.kt,那么其中的内联模块的文件名就是该文件名。例如:
🌐 The inline module file name has to match the native module name (which needs to be unique in your whole app). If you have a SimpleModule.kt, then the inline module inside it has that file name. For example:
// SimpleModule.kt // ... class SimpleModule: Module() { // Note that the class name has to match the filename. override fun definition() = ModuleDefinition { // Name("SimpleModule") // Note that `Name` also has to match the filename. So you can just omit it. } }