我有一个同构的反应/通量(alt)实现。
我正在尝试将项目从 browserify 转换为 webpack。
考虑到我的 React 类可能如下所示:
var dataAccess = require('../server/data-access');
var MyReactClass = React.createClass({
statics: {
/**
* This gets called by the containing component, so that each class
* handles its own data fetching.
* This part is obviously irrelevant in the client since the
* fetching is only done server-side and the result is used
* to populate the Alt.js store
*/
getData: function () {
return dataAccess.fetchData(
);
}
}...
我想在运行 webpack 时避免捆绑整个“服务器”文件夹,但是当我这样做时(通过加载器配置中的排除),事情会以一种奇怪的方式中断:
ERROR in ./react/react-routes.js
Module parse failed: C:\project\react\react-routes.js Line 19: Unexpected token <
You may need an appropriate loader to handle this file type.
| var routes = (
|
| <Route name="App" path="/" handler={App}>
|
| <DefaultRoute name="Default Route" handler={Main}/>
@ ./client/index.js 5:18-50
如果我返回“服务器”,我会在转换 mongojs 的依赖项(“net”等)时遇到错误,我认为这不是正确的方向。
如果我删除 react-routes.js 中对我的反应类的所有要求,则 webpack 能够成功完成。由此我了解到问题确实在于我的类中有服务器代码。
在 browserify 中,我可以通过使用 getData() 函数中的“数据访问”和其他服务器文件的需求来克服这个问题,但是使用 webpack 时我到目前为止还没有运气。
我的忽略/排除规则应该是什么,我应该如何实施它们?
谢谢。