diff --git a/src/index.js b/src/app.js similarity index 75% rename from src/index.js rename to src/app.js index 8f26974..3cc2597 100644 --- a/src/index.js +++ b/src/app.js @@ -19,7 +19,6 @@ import 'babel-polyfill'; -import renderHome from './components/Home'; import renderUser from './components/User'; import initDevelopmentHelpers from './initDevelopmentHelpers'; @@ -27,17 +26,4 @@ import initDevelopmentHelpers from './initDevelopmentHelpers'; // Feel free to not think about this call. initDevelopmentHelpers(); -const path = window.location.pathname; - -switch (path) { - case '/': - renderHome(document.querySelector('#root')); - break; - - case '/users/': - renderUser(document.querySelector('#root')); - break; - - default: - throw new Error('Unknown page. Try going to / or /users/'); -} +renderUser(document.querySelector('#root')); diff --git a/src/landing.js b/src/landing.js new file mode 100644 index 0000000..50ec302 --- /dev/null +++ b/src/landing.js @@ -0,0 +1,15 @@ +/** + * This is the app entry point. It detects the current page + * and renders the corresponding component. + */ + +import 'babel-polyfill'; + +import renderHome from './components/Home'; +import initDevelopmentHelpers from './initDevelopmentHelpers'; + +// This sets up things that help you during development. +// Feel free to not think about this call. +initDevelopmentHelpers(); + +renderHome(document.querySelector('#root')); diff --git a/webpack.config.js b/webpack.config.js index e2ef2f5..5700c55 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -26,7 +26,8 @@ console.log( module.exports = { entry: { - main: './src/index.js', + app: './src/app.js', + landing: './src/landing.js', }, output: { path: path.resolve(__dirname, 'public', 'build'), @@ -67,11 +68,13 @@ module.exports = { // Emit HTML files that serve the app new HtmlWebpackPlugin({ template: 'src/templates/landing.html', + chunks: ['landing', 'vendor', 'runtime'], filename: path.resolve(__dirname, 'public/index.html'), alwaysWriteToDisk: true, }), new HtmlWebpackPlugin({ template: 'src/templates/app.html', + chunks: ['app', 'vendor', 'runtime'], filename: path.resolve(__dirname, 'public/users/index.html'), alwaysWriteToDisk: true, }),