Skip to content

Instantly share code, notes, and snippets.

@fenos
Last active February 17, 2017 17:08
Show Gist options
  • Save fenos/4dd8c7f4b9f21e5e670e8dd8ef2ca623 to your computer and use it in GitHub Desktop.
Save fenos/4dd8c7f4b9f21e5e670e8dd8ef2ca623 to your computer and use it in GitHub Desktop.
const HappyPack = require('happypack')
module.exports = happyPack
function happyPack (blocks = [], options = {}) {
const happyThreadPool = HappyPack.ThreadPool({ size: options.size || 5 })
return (context, webpackConfig) => {
const loaders = [];
const plugins = blocks.map((loader, id) => {
const block = loader(context, webpackConfig) // invoke block to get info
const cacheKey = `cache-file-${id}` // generate cache key
loaders.push({
test: block.test,
loaders: [`happypack/loader?id=${cacheKey}`],
})
return new HappyPack({
loaders: block.module.loaders,
threadPool: happyThreadPool,
})
})
return {
module: {
loaders,
},
plugins,
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment