Skip to content

Commit

Permalink
feat: make dynamic import disabling more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinl committed Feb 22, 2018
1 parent 3b55983 commit d7dec7d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
2 changes: 2 additions & 0 deletions common/js/pages/Todos/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Loadable from 'react-loadable';
import { Loading } from 'components/common';
import { fetchTodos } from 'actions/todos';

// NOTE: To turn off dynamic imports, import this container normally using:
// import TodosContainer from 'containers/Todos';
const TodosContainer = Loadable({
loader: () => import('../../containers/Todos'),
loading: Loading
Expand Down
14 changes: 7 additions & 7 deletions server/renderer/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ export default function handleRender(req, res) {
</Provider>
);

if (!config.enableDynamicImports) {
return component;
if (config.enableDynamicImports) {
return (
<Loadable.Capture report={moduleName => modules.push(moduleName)}>
{component}
</Loadable.Capture>
);
}

return (
<Loadable.Capture report={moduleName => modules.push(moduleName)}>
{component}
</Loadable.Capture>
);
return component;
};

// Execute the render only after all promises have been resolved.
Expand Down
17 changes: 2 additions & 15 deletions webpack/development.hot.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const entry = [

// Additional plugins
let plugins = [
...baseConfig.plugins,
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.NamedModulesPlugin()
Expand All @@ -31,9 +32,6 @@ if (!config.enableDynamicImports) {
}));
}

// Additional loaders
const loaders = [];

const webpackConfig = {
...baseConfig,
devtool: 'eval',
Expand All @@ -44,18 +42,7 @@ const webpackConfig = {
...baseConfig.entry.app
]
},
plugins: [
// don't use the first plugin (isomorphic plugin)
...baseConfig.plugins,
...plugins
],
module: {
...baseConfig.module,
rules: [
...baseConfig.module.rules,
...loaders
]
}
plugins
};

console.info('Firing up Webpack dev server...\n');
Expand Down

0 comments on commit d7dec7d

Please sign in to comment.