【发布时间】: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