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

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-))/]
    }*/]
  }


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值