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

Allow query-param cache busting in chunk names #229

Merged
merged 2 commits into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
37 changes: 36 additions & 1 deletion packages/server/__fixtures__/stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"letters-B": "letters-B.js",
"letters-C": "letters-C.js",
"letters-D": "letters-D.js",
"letters-E": [
"letters-E.css?param",
"letters-E.js?param"
],
"main": [
"main.css",
"main.js"
Expand Down Expand Up @@ -69,6 +73,26 @@
"letters-D"
]
},
{
"name": "letters-E.css?param",
"size": 517,
"chunks": [
"letters-E"
],
"chunkNames": [
"letters-E"
]
},
{
"name": "letters-E.js?param",
"size": 517,
"chunks": [
"letters-E"
],
"chunkNames": [
"letters-E"
]
},
{
"name": "main.css",
"size": 16,
Expand Down Expand Up @@ -219,6 +243,17 @@
"children": {},
"childAssets": {}
},
"letters-E": {
"chunks": [
"letters-E"
],
"assets": [
"letters-E.css?param",
"letters-E.js?param"
],
"children": {},
"childAssets": {}
},
"moment": {
"chunks": [],
"assets": [],
Expand Down Expand Up @@ -298,4 +333,4 @@
"name": "mini-css-extract-plugin node_modules/css-loader/index.js!src/client/main.css"
}
]
}
}
2 changes: 1 addition & 1 deletion packages/server/src/ChunkExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class ChunkExtractor {
createChunkAsset({ filename, chunk, type, linkType }) {
return {
filename,
scriptType: extensionToScriptType(path.extname(filename).toLowerCase()),
scriptType: extensionToScriptType(path.extname(filename).split('?')[0].toLowerCase()),
chunk,
url: this.resolvePublicUrl(filename),
path: path.join(this.outputPath, filename),
Expand Down
116 changes: 116 additions & 0 deletions packages/server/src/ChunkExtractor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ describe('ChunkExtrator', () => {
`)
})

it('should allow for query params in chunk names', () => {
extractor.addChunk('letters-E')
expect(extractor.getScriptTags()).toMatchInlineSnapshot(`
"<script>window.__LOADABLE_REQUIRED_CHUNKS__ = [\\"letters-E\\"];</script>
<script async data-chunk=\\"letters-E\\" src=\\"/dist/node/letters-E.js?param\\"></script>
<script async data-chunk=\\"main\\" src=\\"/dist/node/main.js\\"></script>"
`)
})

it('should add extra props if specified', () => {
extractor.addChunk('letters-A')
expect(extractor.getScriptTags({ nonce: 'testnonce' }))
Expand Down Expand Up @@ -113,6 +122,31 @@ Array [
`)
})

it('should allow for query params in chunk names', () => {
extractor.addChunk('letters-E')
expect(extractor.getScriptElements()).toMatchInlineSnapshot(`
Array [
<script
dangerouslySetInnerHTML={
Object {
"__html": "window.__LOADABLE_REQUIRED_CHUNKS__ = [\\"letters-E\\"];",
}
}
/>,
<script
async={true}
data-chunk="letters-E"
src="/dist/node/letters-E.js?param"
/>,
<script
async={true}
data-chunk="main"
src="/dist/node/main.js"
/>,
]
`)
})

it('should add extra props if specified', () => {
extractor.addChunk('letters-A')
expect(extractor.getScriptElements({ nonce: 'testnonce' }))
Expand Down Expand Up @@ -158,6 +192,14 @@ Array [
`)
})

it('should allow for query params in chunk names', () => {
extractor.addChunk('letters-E')
expect(extractor.getStyleTags()).toMatchInlineSnapshot(`
"<link data-chunk=\\"letters-E\\" rel=\\"stylesheet\\" href=\\"/dist/node/letters-E.css?param\\">
<link data-chunk=\\"main\\" rel=\\"stylesheet\\" href=\\"/dist/node/main.css\\">"
`)
})

it('should add extraProps if specified', () => {
extractor.addChunk('letters-A')
expect(extractor.getStyleTags({ nonce: 'testnonce' }))
Expand Down Expand Up @@ -241,6 +283,24 @@ Array [
`)
})

it('should allow for query params in chunk names', () => {
extractor.addChunk('letters-E')
expect(extractor.getStyleElements()).toMatchInlineSnapshot(`
Array [
<link
data-chunk="letters-E"
href="/dist/node/letters-E.css?param"
rel="stylesheet"
/>,
<link
data-chunk="main"
href="/dist/node/main.css"
rel="stylesheet"
/>,
]
`)
})

it('should add extraProps if specified', () => {
extractor.addChunk('letters-A')
expect(extractor.getStyleElements({ nonce: 'testnonce' }))
Expand Down Expand Up @@ -337,6 +397,18 @@ h1 {
`)
})

it('should allow for query params in chunk names', () => {
extractor.addChunk('letters-E')
expect(extractor.getLinkTags()).toMatchInlineSnapshot(`
"<link data-chunk=\\"letters-E\\" rel=\\"preload\\" as=\\"style\\" href=\\"/dist/node/letters-E.css?param\\">
<link data-chunk=\\"letters-E\\" rel=\\"preload\\" as=\\"script\\" href=\\"/dist/node/letters-E.js?param\\">
<link data-chunk=\\"main\\" rel=\\"preload\\" as=\\"style\\" href=\\"/dist/node/main.css\\">
<link data-chunk=\\"main\\" rel=\\"preload\\" as=\\"script\\" href=\\"/dist/node/main.js\\">
<link data-parent-chunk=\\"main\\" rel=\\"preload\\" as=\\"script\\" href=\\"/dist/node/letters-C.js\\">
<link data-parent-chunk=\\"main\\" rel=\\"prefetch\\" as=\\"script\\" href=\\"/dist/node/letters-D.js\\">"
`)
})

it('should add extraProps if specified', () => {
extractor.addChunk('letters-A')
expect(extractor.getLinkTags({ nonce: 'testnonce' }))
Expand Down Expand Up @@ -427,6 +499,50 @@ Array [
`)
})

it('should allow for query params in chunk names', () => {
extractor.addChunk('letters-E')
expect(extractor.getLinkElements()).toMatchInlineSnapshot(`
Array [
<link
as="style"
data-chunk="letters-E"
href="/dist/node/letters-E.css?param"
rel="preload"
/>,
<link
as="script"
data-chunk="letters-E"
href="/dist/node/letters-E.js?param"
rel="preload"
/>,
<link
as="style"
data-chunk="main"
href="/dist/node/main.css"
rel="preload"
/>,
<link
as="script"
data-chunk="main"
href="/dist/node/main.js"
rel="preload"
/>,
<link
as="script"
data-parent-chunk="main"
href="/dist/node/letters-C.js"
rel="preload"
/>,
<link
as="script"
data-parent-chunk="main"
href="/dist/node/letters-D.js"
rel="prefetch"
/>,
]
`)
})

it('should add extraProps if specified', () => {
extractor.addChunk('letters-A')
expect(extractor.getLinkElements({ nonce: 'testnonce' }))
Expand Down