Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
compilation.plugin('optimize-chunk-assets', (chunks, callback) => {
const { assets } = compilation
const spriteAssets = _.pickBy(assets, (value, key) => key.startsWith('sprite-'))
if (_.isEmpty(spriteAssets) || _.isNil(spriteAssets)) throw new Error('Sprites are not compiled!')
const spriteSources = _.transform(spriteAssets, (result, value, key) => result[key.replace(/(sprite-|.svg)/g, '')] = value.source())
getAllModules(compilation).forEach((module) => {
replaceInModuleSource(module, {
__SPRITE_SOURCES__: JSON.stringify(spriteSources)
})
})
callback()
})
})