I am trying to include in an Ionic2-Angular4 project some react components but without success. For the building process I am using ionic scripts
"build": "ionic-app-scripts build",
"serve": "ionic-app-scripts serve",
I have updated also on the tsconfig.json the compilerOptions with the below option :
{
"compilerOptions": {
"jsx": "react",
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2015"
],
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5"
},
"include": [
"src/**/*.ts",
"src/**/*.tsx"
],
"exclude": [
"node_modules"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
And the webpack.config.ts as below :
var path = require('path');
var webpack = require('webpack');
var ionicWebpackFactory = require(process.env.IONIC_WEBPACK_FACTORY);
module.exports = {
entry: process.env.IONIC_APP_ENTRY_POINT,
output: {
path: '{{BUILD}}',
publicPath: 'build/',
filename: process.env.IONIC_OUTPUT_JS_FILE_NAME,
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
},
devtool: process.env.IONIC_SOURCE_MAP_TYPE,
resolve: {
extensions: ['.ts', '.js', '.tsx', '.json'],
modules: [path.resolve('node_modules')]
},
module: {
loaders: [
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.tsx?$/,
loader: process.env.IONIC_WEBPACK_TRANSPILE_LOADER
},
{
test: /\.js$/,
loader: process.env.IONIC_WEBPACK_TRANSPILE_LOADER
}
]
},
plugins: [
ionicWebpackFactory.getIonicEnvironmentPlugin(),
new webpack.EnvironmentPlugin(['IONIC_ENV'])
],
node: {
fs: 'empty',
net: 'empty',
tls: 'empty'
}
};
Also I have added on package.json the below libraries :
"react": "^15.6.1",
"react-dev-utils": "^4.0.1",
"react-dom": "^15.6.1",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
Every time I am trying to build, the build is finished correctly but I am getting the error :
Error: Cannot find module "./TestBar"
The TestBar is a ReactComponent which I am trying to import it on an Angular component. The code is below for
TestBar.tsx file:
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Injector } from '@angular/core';
import { ValueStore} from './redux/list.store';
import {Model} from './model';
interface ReactChildComponentViewProps {
store: ValueStore;
injector: Injector;
}
let TestBar = React.createClass<ReactChildComponentViewProps, any> ({
getInitialState: function () {
let model: Model = this.props.injector.get(Model);
console.log('Using Angular 2 injector in React body, model.uuid: ' + model);
this.props.store.store.subscribe(() => {
this.setState({
'elements': this.props.store.store.getState()
});
});
return {
'title': this.props.title,
'elements': this.props.store.store.getState()
};
},
render() {
return (
<div>aaaa</div>
);
}
});
export class ReactChildComponentView {
static initialize( store, injector, containerId) {
ReactDOM.render(<TestBar store={store} injector={injector}/>, document.getElementById(containerId));
}
}
Have ever someone tried something similar ?