Skip to content

Instantly share code, notes, and snippets.

@ooflorent
Last active August 28, 2017 19:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ooflorent/d4116584cc45a19c835b to your computer and use it in GitHub Desktop.
Save ooflorent/d4116584cc45a19c835b to your computer and use it in GitHub Desktop.
Simplify extension management in webpack
const ext = (...suffix) => new RegExp(`\\.(?:${ suffix.join('|') })(?:[?#].*)?$`)
const loaders = [
// Traditional cases
{ test: ext('css'), loaders: ['style', 'css'] }, // single
{ test: ext('js', 'jsx', 'es6'), loaders: ['babel'] }, // multiple
// Complex case: Font-Awesome adds query strings and/or hashs to files
{ test: ext('otf', 'eot', 'svg', 'ttf', 'woff', 'woff2'), loaders: ['file?name=[name].[ext]'] },
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment