Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4 steps to convert angular app to angular lazy module #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"yoshi": {
"entry": {
"react-client": "./react/client.js",
"angular-client": "./angular/client.js"
"angular-client": "./angular/client.js",
"angular-manifest": "./angular/manifest.js"
}
}
}
17 changes: 17 additions & 0 deletions src/angular/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {ModuleRegistry, AngularLazyComponent} from 'react-module-container';

class NgMainApp extends AngularLazyComponent {
constructor(props) {
super(props, {
files: [
`${props.topology.staticsBaseUrl}angular-client.css`,
`${props.topology.staticsBaseUrl}angular-client.bundle.js`
],
module: 'myApp',
component: 'main-app',
unloadStylesOnDestroy: true
});
}
}

ModuleRegistry.registerComponent('angular.main', () => NgMainApp);
6 changes: 1 addition & 5 deletions src/index.vm
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@
<meta charset="utf-8">
<title>${title}</title>
<link rel="stylesheet" href="${clientTopology.staticsBaseUrl}react-client.css">
<link rel="stylesheet" href="${clientTopology.staticsBaseUrl}angular-client.css">
</head>

<body>
<div id="react-root"></div>

<div id="angular-root" ng-app="myApp">
<main-app></main-app>
</div>
<script>
window.__BASEURL__ = '${basename}';
window.__LOCALE__ = '${locale}';
window.__STATICS_BASE_URL__ = '${clientTopology.staticsBaseUrl}';
</script>
<script src="${clientTopology.staticsBaseUrl}angular-manifest.bundle.js"></script>
<script src="${clientTopology.staticsBaseUrl}react-client.bundle.js"></script>
<script src="${clientTopology.staticsBaseUrl}angular-client.bundle.js"></script>
</body>

</html>
12 changes: 12 additions & 0 deletions src/react/components/App/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import React from 'react';
import s from './App.scss';
import {ModuleRegistry} from 'react-module-container';

class App extends React.Component {
componentWillMount() {
this.setState(() => ({
AngularComponent: ModuleRegistry.component('angular.main')
}));
}
render() {
const AngularComponent = this.state.AngularComponent;
const topology = {
staticsBaseUrl: window.__STATICS_BASE_URL__
};

return (
<div className={s.root}>
<div className={s.header}>
<h2>{'Hello React World!'}</h2>
</div>
<AngularComponent topology={topology}/>
</div>
);
}
Expand Down