packaton 0.0.25 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/app-prod.js +12 -2
- package/src/config.js +1 -0
- package/src/plugins-prod/netiflyAndCloudflareHeadersPlugin.js +8 -26
package/index.d.ts
CHANGED
package/package.json
CHANGED
package/src/app-prod.js
CHANGED
|
@@ -55,6 +55,11 @@ export async function buildStaticPages(config) {
|
|
|
55
55
|
const pages = await crawlRoutes(server.address(), docs.routes)
|
|
56
56
|
const mediaHashes = await renameMediaWithHashes(pDist, MEDIA_REL_URL)
|
|
57
57
|
|
|
58
|
+
const headers = {
|
|
59
|
+
['/' + MEDIA_REL_URL + '/*']: [
|
|
60
|
+
['Cache-Control', 'public,max-age=31536000,immutable']
|
|
61
|
+
]
|
|
62
|
+
}
|
|
58
63
|
const cspByRoute = []
|
|
59
64
|
for (const [route, rawHtml] of pages) {
|
|
60
65
|
const doc = new HtmlCompiler(rawHtml, pSource, {
|
|
@@ -71,13 +76,18 @@ export async function buildStaticPages(config) {
|
|
|
71
76
|
await doc.inlineMinifiedCSS()
|
|
72
77
|
await doc.inlineMinifiedJS()
|
|
73
78
|
write(join(pDist, route + config.outputExtension), doc.html)
|
|
74
|
-
|
|
79
|
+
|
|
80
|
+
const r = route === '/index' ? '/' : route
|
|
81
|
+
headers[r] ??= []
|
|
82
|
+
headers[r].push(['Content-Security-Policy', doc.csp()])
|
|
83
|
+
for (const h of config.routeHeaders)
|
|
84
|
+
headers[r].push(h)
|
|
75
85
|
}
|
|
76
86
|
|
|
77
87
|
sitemapPlugin(config, docs.routes)
|
|
78
88
|
reportSizesPlugin(config, docs.routes)
|
|
79
89
|
cspNginxMapPlugin(config, cspByRoute)
|
|
80
|
-
|
|
90
|
+
write(join(config.outputDir, '_headers'), netiflyAndCloudflareHeadersPlugin(headers))
|
|
81
91
|
}
|
|
82
92
|
catch (error) {
|
|
83
93
|
reject(error)
|
package/src/config.js
CHANGED
|
@@ -1,28 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
export function netiflyAndCloudflareHeadersPlugin(config, cspByRoute, relMediaURL) {
|
|
11
|
-
const out = join(join(config.outputDir), '_headers')
|
|
12
|
-
|
|
13
|
-
const cspHeaders = cspByRoute.map(([route, csp]) => {
|
|
14
|
-
const r = route === '/index'
|
|
15
|
-
? '/'
|
|
16
|
-
: route
|
|
17
|
-
return [
|
|
18
|
-
r,
|
|
19
|
-
` Content-Security-Policy: ${csp}`,
|
|
20
|
-
` Cache-Control: public,max-age=60`
|
|
21
|
-
].join('\n')
|
|
22
|
-
})
|
|
23
|
-
cspHeaders.push(`/${relMediaURL}/*`)
|
|
24
|
-
cspHeaders.push(' Cache-Control: public,max-age=31536000,immutable')
|
|
25
|
-
|
|
26
|
-
write(out, cspHeaders.join('\n'))
|
|
1
|
+
export function netiflyAndCloudflareHeadersPlugin(opts) {
|
|
2
|
+
let result = []
|
|
3
|
+
for (const [route, headers] of Object.entries(opts)) {
|
|
4
|
+
result.push(route)
|
|
5
|
+
for (const [h, v] of headers)
|
|
6
|
+
result.push(` ${h}: ${v}`)
|
|
7
|
+
}
|
|
8
|
+
return result.join('\n')
|
|
27
9
|
}
|
|
28
10
|
|