2016-12-31 12:46:23 +00:00
|
|
|
export default class JsonPagesPlugin {
|
|
|
|
apply (compiler) {
|
|
|
|
compiler.plugin('after-compile', (compilation, callback) => {
|
|
|
|
const pages = Object
|
|
|
|
.keys(compilation.assets)
|
2017-01-02 04:06:49 +00:00
|
|
|
.filter((filename) => /^bundles[/\\]pages.*\.js$/.test(filename))
|
2016-12-31 12:46:23 +00:00
|
|
|
|
|
|
|
pages.forEach((pageName) => {
|
|
|
|
const page = compilation.assets[pageName]
|
|
|
|
delete compilation.assets[pageName]
|
|
|
|
|
|
|
|
const content = page.source()
|
|
|
|
const newContent = JSON.stringify({ component: content })
|
|
|
|
|
|
|
|
compilation.assets[`${pageName}on`] = {
|
|
|
|
source: () => newContent,
|
|
|
|
size: () => newContent.length
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
callback()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|