Last active
February 17, 2017 17:08
-
-
Save fenos/4dd8c7f4b9f21e5e670e8dd8ef2ca623 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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