react-native 打包成web项目用于微信公众号,以及问题汇总

来源:互联网 发布:淘宝客后台管理系统 编辑:程序博客网 时间:2024/06/05 07:49

https://github.com/taobaofed/react-web#fix-platform-differences

如果打包成功,可以作为公众号的自定义菜单项目。

以下是自己在按照上面链接的步骤运行时候遇到的问题

问题汇总:

1.Cannot resolve module 'react/lib/ReactMount'

原因:好像是在react  14.x 版本之后,ReactMount从react中分离了,挪到react-dom模块了,而如果引用了react-hot-loader v1就会报这个错,因为他依赖的是老版本的react

解决:在使用高版本的react后需要使用react-hot-loader  V3.X版本的,我是用的是 

"react-hot-loader": "3.0.0-beta.6"

我的package.json内容如下:

{  "name": "firstReactWeb",  "version": "0.0.1",  "private": true,  "dependencies": {    "react-web": "0.4.6"  },  "devDependencies": {    "react": "^15.4.2",    "babel-loader": "^6.2.5",    "babel-preset-react-native": "^1.9.0",    "babel-preset-stage-1": "^6.16.0",    "haste-resolver-webpack-plugin": "^0.2.2",    "json-loader": "^0.5.4",    "webpack": "^1.13.2",    "webpack-dev-server": "^1.16.1",    "webpack-html-plugin": "^0.1.1",    "react-dom":"15.3",    "react-hot-loader": "3.0.0-beta.6"  }}

2.React Hot Loader: The Webpack loader is now exported separately. If you use Babel, we recommend that you remove "react-hot-loader" from the "loaders" section of your Webpack configuration altogether, and instead add "react-hot-loader/babel" to the "plugins" section of your .babelrc file. If you prefer not to use Babel, replace "react-hot-loader" or "react-hot" with "react-hot-loader/webpack" in the "loaders" section of your Webp
ack configuration.出现提示loader选择,使用baber或者hot-loader,我是用的是hot-loader,以下是解决方法

解决:修改webpack-config.js文件module里面的loader,注释掉以下部分,添加新的

module: {    loaders: [{      test: /\.json$/,      loader: 'json',    },     {//开始********************************************      test: /\.jsx?$/,      loader: 'react-hot-loader/webpack',      include: [config.paths.src],      exclude: [/node_modules/]    }//结束***********************************************        /*, {            test: /\.jsx?$/,            loader: 'react-hot',            include: [config.paths.src],            exclude: [/node_modules/]        }, {      test: /\.jsx?$/,      loader: 'babel',      query: {        presets: ['react-native', 'stage-1']      },      include: [config.paths.src],      exclude: [path.sep === '/' ? /(node_modules\/(?!react-))/ : /(node_modules\\(?!react-))/]    }*/]  }