diff --git a/.babelrc b/.babelrc index fbd6da0..b88ce11 100644 --- a/.babelrc +++ b/.babelrc @@ -1,4 +1,5 @@ { + "plugins": ["@loadable/babel-plugin"], "presets": [ "@babel/preset-env", "@babel/preset-react" diff --git a/client/loaders/DetailsLoader.jsx b/client/loaders/DetailsLoader.jsx index 03e45c1..5bddd06 100644 --- a/client/loaders/DetailsLoader.jsx +++ b/client/loaders/DetailsLoader.jsx @@ -5,7 +5,16 @@ import './spinner.css'; const slug = item => item.toLowerCase().split(' ').join('-'); -const DetailsLoader = loadable(props => import(`../patterns/${slug(props.pattern)}/Details`), { +// In order to create a link to another page that is dynamically loaded (via ), +// the page chunks have to be loadable by @loadable. +// We have to add a magic comment /* #__LOADABLE__ */ here +// and the following plugin to Babel's settings (.babelrc): +// { +// "plugins": ["@loadable/babel-plugin"], +// } +const loadDetails = /* #__LOADABLE__ */ (props) => import(`../patterns/${slug(props.pattern)}/Details`) + +const DetailsLoader = loadable(loadDetails, { fallback: (
diff --git a/package-lock.json b/package-lock.json index 4ceb67b..aa5b531 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1942,6 +1942,15 @@ "regenerator-runtime": "^0.13.2" } }, + "@loadable/babel-plugin": { + "version": "5.10.3", + "resolved": "https://registry.npmjs.org/@loadable/babel-plugin/-/babel-plugin-5.10.3.tgz", + "integrity": "sha512-Izo4QX526f/Czvdot1izg0DtA5DfJEW5RUN28/9wt+62It4xKhVv9l0NNcTEL39xJXj7lsE4k5Z6eCBSETpHmw==", + "dev": true, + "requires": { + "@babel/plugin-syntax-dynamic-import": "^7.2.0" + } + }, "@loadable/component": { "version": "5.10.3", "resolved": "https://registry.npmjs.org/@loadable/component/-/component-5.10.3.tgz", diff --git a/package.json b/package.json index 963cbad..94ff105 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@babel/core": "^7.7.4", "@babel/preset-env": "^7.7.4", "@babel/preset-react": "^7.7.4", + "@loadable/babel-plugin": "^5.10.3", "babel-loader": "^8.0.6", "css-loader": "^3.2.0", "html-webpack-plugin": "^3.2.0",