From 5142179acd1600dd09b70cf11db2a55e018a9ff7 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 18 Sep 2018 15:03:20 +0300 Subject: dynamic import --- vnext/package.json | 5 ++++- vnext/src/index.js | 15 +++++++++------ vnext/src/style/main.css | 4 ++-- vnext/src/views/index.html | 4 +++- vnext/webpack.config.js | 27 +++++++++++++++++++-------- vnext/yarn.lock | 14 +++++++++++++- 6 files changed, 50 insertions(+), 19 deletions(-) (limited to 'vnext') diff --git a/vnext/package.json b/vnext/package.json index ca08ce44..965e2997 100644 --- a/vnext/package.json +++ b/vnext/package.json @@ -14,6 +14,7 @@ "@babel/core": "7.1.0", "@babel/plugin-proposal-class-properties": "7.1.0", "@babel/plugin-proposal-object-rest-spread": "7.0.0", + "@babel/plugin-syntax-dynamic-import": "^7.0.0", "@babel/preset-env": "7.1.0", "@babel/preset-react": "7.0.0", "autoprefixer": "^9.1.5", @@ -61,7 +62,8 @@ { "useBuiltIns": true } - ] + ], + "@babel/plugin-syntax-dynamic-import" ], "presets": [ "@babel/preset-env", @@ -77,6 +79,7 @@ "react-content-loader": "^3.1.2", "react-cookies": "^0.1.0", "react-dom": "^16.5.1", + "react-loadable": "^5.5.0", "react-router-dom": "^4.3.1" } } diff --git a/vnext/src/index.js b/vnext/src/index.js index 24fe9352..74e36d84 100644 --- a/vnext/src/index.js +++ b/vnext/src/index.js @@ -1,11 +1,14 @@ import React from 'react'; import ReactDOM from 'react-dom'; +import Loadable from 'react-loadable'; -import App from './App'; +const Juick = Loadable({ + loader: () => import('./App'), + loading: () =>
Loading...
+}); -let container = document.createElement('div'); -ReactDOM.render(, container); -let body = document.getElementById('content').parentNode; -body.replaceChild(container.getElementsByTagName('header')[0], body.querySelector('#header')); -body.replaceChild(container.querySelector('#content'), body.querySelector('#content')); +const JuickApp = () => ( + +); +ReactDOM.render(, document.getElementById('body')); diff --git a/vnext/src/style/main.css b/vnext/src/style/main.css index 6d78c7eb..77cc56cb 100644 --- a/vnext/src/style/main.css +++ b/vnext/src/style/main.css @@ -87,7 +87,7 @@ noscript article { background: #006699; color: #fff; } -body > header { +#body > header { position: fixed; top: 0; width: 100%; @@ -138,7 +138,7 @@ body > header { min-width: 310px; width: auto; } - body > header { + #body > header { margin-bottom: 15px; } } diff --git a/vnext/src/views/index.html b/vnext/src/views/index.html index e5862bc1..f9fb7e72 100644 --- a/vnext/src/views/index.html +++ b/vnext/src/views/index.html @@ -42,7 +42,8 @@ - + +