Skip to content
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

Merged
merged 18 commits into from
Dec 31, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make Json pages even if there's an error.
  • Loading branch information
arunoda committed Dec 30, 2016
commit b6daa2879043daa389c7f34aacf95e8e3699bc49
5 changes: 4 additions & 1 deletion server/build/plugins/json-pages-plugin.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
export default class JsonPagesPlugin {
Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me 👍

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change the extension to .json ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That can be done. I'll try it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

})

callback()
Expand Down
4 changes: 2 additions & 2 deletions server/build/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ export default async function createCompiler (dir, { dev = false, quiet = false
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new DetachPlugin(),
new JsonPagesPlugin(),
new DynamicEntryPlugin(),
new UnlinkFilePlugin(),
new WatchRemoveEventPlugin(),
new WatchPagesPlugin(dir)
new WatchPagesPlugin(dir),
new JsonPagesPlugin()
)
if (!quiet) {
plugins.push(new FriendlyErrorsWebpackPlugin())
Expand Down