React + React Native in same project
Helo,
I have a project for web using react
and for native using react-native
and share some code.
The react-native
is working, but the web version is not working in the same code base, if i remove the react-native
code and libraries the web version is working.
I think the problem is on webpack
configuration, i have tryed a lot o version but in snot working.
For the web to start the server i use:
"webpack-dev-server --content-base dist/ --config webpack/web.dev.config.js --port 3000 --inline --hot --colors --historyApiFallback",
My webpack
config file:
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(),
],
}
And the errors, a few of them:
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
Comments
Post a Comment