-
Notifications
You must be signed in to change notification settings - Fork 27.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Gzip support for JSON pages #571
Changes from 1 commit
bc2774a
b6daa28
6dd5db3
bff2435
901915d
6401e33
3af72f1
81ba173
298629f
b0b04a7
1e0e7a8
e24f261
7a04f38
79d566c
352fe77
20d01ba
343cb92
370189b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
export default class JsonPagesPlugin { | ||
apply (compiler) { | ||
compiler.plugin('emit', (compilation, callback) => { | ||
compiler.plugin('after-compile', (compilation, callback) => { | ||
const pages = Object | ||
.keys(compilation.assets) | ||
.filter((filename) => /^bundles\/pages/.test(filename)) | ||
|
||
pages.forEach((pageName) => { | ||
const page = compilation.assets[pageName] | ||
if (page.jsoned) return | ||
|
||
const content = page.source() | ||
const newContent = JSON.stringify({ component: content }) | ||
page.source = () => newContent | ||
page.size = () => newContent.length | ||
page.jsoned = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we change the extension to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. That can be done. I'll try it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
}) | ||
|
||
callback() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nkzawa This is my first webpack plugin.
Could you check whether I have done something ugly here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me 👍