Skip to content

Instantly share code, notes, and snippets.

@matheus1lva
Created January 22, 2019 12:04
Show Gist options
  • Save matheus1lva/efe46c74f0e8b681a9402a144195734a to your computer and use it in GitHub Desktop.
Save matheus1lva/efe46c74f0e8b681a9402a144195734a to your computer and use it in GitHub Desktop.
code splitting/dynamic import
// generates a single file for your component.js
// only when used.
// This returns a promise, which needs to be resolved.
import('./components/component.js')
// creates a chunk for each file inside your components folder
// This is called require context (which require.context is used under the hood)
// Webpack is smart enough to do that for you!
const myComponents = (componentName) => import(`./components/${componentName}.js`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment