Skip to content

Instantly share code, notes, and snippets.

@pushkar100
Last active October 18, 2020 08:45
Show Gist options
  • Save pushkar100/22461524f3c41d6935d7bd99b27821e5 to your computer and use it in GitHub Desktop.
Save pushkar100/22461524f3c41d6935d7bd99b27821e5 to your computer and use it in GitHub Desktop.
Chunk exports with partial split
// (B) What you need to manually do to import only A from the dynamic chunk:
/* ./utilities.js */
export const add = (a, b) => a + b
export const subtract = (a, b) => a - b
export const multiply = (a, b) => a * b
export const divide = (a, b) => a / b
const power = (a, b) => Math.pow(a, b)
export default power
/* NEW MODULE NEEDS TO BE CREATED: ./utilities-add.js */
export { add } from './utilities'
/* ./main.js */
import('./utilities-add.js')
.then(module => {
console.log(module.add)
// Only module.add is available and not the other exports!
// The chunk that is created too will be smaller
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment