Last active
February 20, 2018 18:05
-
-
Save gianlucacandiotti/4b2f82aa38d9bcb3ba99b911191df5e5 to your computer and use it in GitHub Desktop.
Dynamic imports with Webpack.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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