Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Last active December 3, 2020 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save james2doyle/97fe6eab114eee22fea4895bd0c44c6b to your computer and use it in GitHub Desktop.
Save james2doyle/97fe6eab114eee22fea4895bd0c44c6b to your computer and use it in GitHub Desktop.
A fastmod snippet that refactors module imports to dynamic imports with wepback chunking enabled
# https://github.com/facebookincubator/fastmod
# old code: `import MyComponent from 'Components/MyComponent.vue';`
# new code: `const MyComponent = () => import(/* webpackChunkName: "MyComponent" */ 'Components/MyComponent.vue');`
# note: you may need to reorder your imports when using a dynamic import
fastmod -m -d ./ --extensions vue \
'import (.*?) from \'(.*?)\';' \
'const ${1} = () => import(/* webpackChunkName: "${1}" */ \'${2}\');'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment