直升机,

我有一个使用 react 的web项目和使用 react-native 的本地项目并共享一些代码 .

react-native 正在运行,但是如果我删除了Web版本正在运行的 react-native 代码和库,则Web版本无法在相同的代码库中运行 .

我认为问题出在 webpack 配置上,我已经尝试了很多o版本但是在snot工作中 .

为了启动服务器的Web我使用:

"webpack-dev-server --content-base dist/ --config webpack/web.dev.config.js --port 3000 --inline --hot --colors --historyApiFallback",

我的 webpack 配置文件:

const path = require('path')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const autoprefixer = require('autoprefixer')

const extractLess = new ExtractTextPlugin('css/style_webpack.css')

module.exports = {
  devtool: 'eval',
  entry: [path.resolve(__dirname, '../src/web/index')],
  cache: true,
  output: {
    path: path.join(__dirname, '../dist'),
    filename: 'bundle.js',
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
          plugins: [
            'transform-object-rest-spread',
            'transform-class-properties',
          ],
          presets: ['es2015', 'react', 'stage-0'],
        },
        include: path.resolve(__dirname, '../src')
      },
      {
        test: /\.less$/i,
        loader: extractLess.extract([
          {
            loader: 'raw-loader',
            options: {
              minimize: false,
              sourceMap: false,
            },
          },
          {
            loader: 'postcss-loader',
            options: {
              plugins: function() {
                return [autoprefixer('>1%', 'ie 10')]
              },
            },
          },
          {
            loader: 'less-loader',
            options: {
              strictMath: false,
              noIeCompat: true,
            },
          },
        ]),
      },
    ],
  },
  plugins: [
    extractLess,
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify('development'),
        PLATFORM_ENV: JSON.stringify('web'),
      },
    }),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin(),
  ],
}

而错误,其中一些:

ERROR in ./~/react-native/Libraries/react-native/react-native-implementation.js
        Module not found: Error: Can't resolve 'AppRegistry' in 'E:\Proiecte\TransparentResidence\asociatie_frontend\node_modules\react-native\Libraries\react-native'
         @ ./~/react-native/Libraries/react-native/react-native-implementation.js 69:29-51
         @ ./src/native/routes/appNavigator.js
         @ ./src/reducers/nav/nav.js
         @ ./src/reducers/index.js
         @ ./src/configureStore.js
         @ ./src/web/index.js
         @ multi ./src/web/index

        ERROR in ./~/react-native/Libraries/react-native/react-native-implementation.js
        Module not found: Error: Can't resolve 'AppState' in 'E:\Proiecte\TransparentResidence\asociatie_frontend\node_modules\react-native\Libraries\react-native'
         @ ./~/react-native/Libraries/react-native/react-native-implementation.js 70:26-45
         @ ./src/native/routes/appNavigator.js
         @ ./src/reducers/nav/nav.js
         @ ./src/reducers/index.js
         @ ./src/configureStore.js
         @ ./src/web/index.js
         @ multi ./src/web/index

    ERROR in ./~/react-native-elements/src/searchbar/SearchBar.js
    Module parse failed: E:\Proiecte\TransparentResidence\asociatie_frontend\node_modules\react-native-elements\src\searchbar\SearchBar.js Unexpected token (14:8)
    You may need an appropriate loader to handle this file type.
    |
    | class SearchBar extends Component {
    |   focus = () => {
    |     this.searchbar.focus();
    |   };
     @ ./~/react-native-elements/src/index.js 16:0-46
     @ ./src/native/routes/appNavigator.js
     @ ./src/reducers/nav/nav.js
     @ ./src/reducers/index.js
     @ ./src/configureStore.js
     @ ./src/web/index.js
     @ multi ./src/web/index

    ERROR in ./~/react-native-elements/src/card/Card.js
    Module parse failed: E:\Proiecte\TransparentResidence\asociatie_frontend\node_modules\react-native-elements\src\card\Card.js Unexpected token (37:4)
    You may need an appropriate loader to handle this file type.
    |     fontFamily,
    |     imageProps,
    |     ...attributes
    |   } = props;
    |
     @ ./~/react-native-elements/src/index.js 24:0-31
     @ ./src/native/routes/appNavigator.js
     @ ./src/reducers/nav/nav.js
     @ ./src/reducers/index.js
     @ ./src/configureStore.js
     @ ./src/web/index.js
     @ multi ./src/web/index

    ERROR in ./~/react-native-elements/src/checkbox/CheckBox.js
    Module parse failed: E:\Proiecte\TransparentResidence\asociatie_frontend\node_modules\react-native-elements\src\checkbox\CheckBox.js Unexpected token (29:4)
    You may need an appropriate loader to handle this file type.
    |     checkedTitle,
    |     fontFamily,
    |     ...attributes
    |   } = props;
    |
     @ ./~/react-native-elements/src/index.js 18:0-43
     @ ./src/native/routes/appNavigator.js
     @ ./src/reducers/nav/nav.js
     @ ./src/reducers/index.js
     @ ./src/configureStore.js
     @ ./src/web/index.js
     @ multi ./src/web/index