【问题标题】:Prevent React Native packager from trying to resolve certain modules防止 React Native 打包器尝试解析某些模块
【发布时间】:2015-09-22 09:25:42
【问题描述】:

我正在尝试将 Browserify 用于我的 React Native 项目。我的想法是,我首先将我的源代码与 Browserify 捆绑在一起,将“react-native”标记为外部模块,然后使用 React Native 打包器将我的包与 React Native 捆绑在一起并提供服务。它可以工作,但打包程序不断为我的模块打印错误:

Unable to resolve module ../../myModule from index.ios.js

有没有办法告诉打包者忽略这些模块?

编辑我的设置示例:

./src/ImportantModule.js:

module.exports = function() { return "Text"; }

./src/ImportantComponent.js:

var React = require('react-native');
var M     = require('./ImportantModule');

var MyApp = React.createClass({
    render: function() {
        var text = M();
        return React.createElement(React.Text, null, text);
    }
});

React.AppRegistry.registerComponent('test', function () { return MyApp; });

然后在项目文件夹中运行:

browserify ./src/ImportantComponent.js --exclude react-native > ./index.ios.js

有效,但打包者抱怨:

Unable to resolve module ./ImportantModule from /Users/.../index.ios.js

我需要 Browserify 的唯一原因是我想使用 aliasify 作为路径别名。有没有办法用 React Native Packager 做到这一点?如果没有,有没有办法隐藏这些“错误”?

【问题讨论】:

    标签: javascript browserify react-native


    【解决方案1】:

    我使用 React-native 的方式是假设它是节点的一个子集。 React-native 不使用 NodeJS 或 Google 的 V8。

    【讨论】:

    • 对不起,但我看不出这与我的问题有什么关系。你能解释一下吗?
    • 你能给我们更多关于你的代码和目录树的例子吗?
    • 抱歉耽搁了,我刚刚添加了一个示例。
    猜你喜欢
    • 2023-02-25
    • 2022-01-17
    • 1970-01-01
    • 2021-02-05
    • 2021-10-29
    • 2019-04-15
    • 2017-10-11
    • 2016-03-23
    • 1970-01-01
    相关资源
    最近更新 更多