Skip to content

Instantly share code, notes, and snippets.

@gianlucacandiotti
Last active February 20, 2018 18:05
Show Gist options
  • Save gianlucacandiotti/4b2f82aa38d9bcb3ba99b911191df5e5 to your computer and use it in GitHub Desktop.
Save gianlucacandiotti/4b2f82aa38d9bcb3ba99b911191df5e5 to your computer and use it in GitHub Desktop.
Dynamic imports with Webpack.
import flow from 'lodash/fp/flow';
import filter from 'lodash/fp/filter';
import reduce from 'lodash/fp/reduce';
const filesPaths = require.context('.', true, /.js$/);
const files = flow(
filter(page => page !== './index.js'),
reduce((acc, page) => {
const [
// eslint-disable-next-line
_,
pageName,
] = page.split`/`;
acc[pageName] = filesPaths(page).default;
return acc;
}, {}),
)(filesPaths.keys());
export default files;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment