mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
25 lines
675 B
JavaScript
25 lines
675 B
JavaScript
export default class JsonPagesPlugin {
|
|
apply (compiler) {
|
|
compiler.plugin('after-compile', (compilation, callback) => {
|
|
const pages = Object
|
|
.keys(compilation.assets)
|
|
.filter((filename) => /^bundles[/\\]pages.*\.js$/.test(filename))
|
|
|
|
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()
|
|
})
|
|
}
|
|
}
|