Skip to content

Commit 914c7fb

Browse files
committed
Add comments and make this releseable.
1 parent 610539d commit 914c7fb

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

server/build/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ function runCompiler (compiler) {
4646
}
4747

4848
async function writeBuildStats (dir) {
49+
// Here we can't use the hash in chunks.
50+
// That's because app.js has no related chunk.
51+
// It's created with merging the few assets. (commons.js and main.js)
52+
// So, we need to generate the hash ourself.
4953
const assetHashMap = {
5054
'app.js': {
5155
hash: await md5File(join(dir, '.next', 'app.js'))

server/build/plugins/combine-assets-plugin.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1+
// This pulgin merge a set of assets into a single asset
2+
// This should be only used with text assets,
3+
// otherwise the result is unpredictable.
14
export default class CombineAssetsPlugin {
5+
constructor ({ input, output }) {
6+
this.input = input
7+
this.output = output
8+
}
9+
210
apply (compiler) {
311
compiler.plugin('after-compile', (compilation, callback) => {
4-
const input = [
5-
'commons.js',
6-
'main.js'
7-
]
8-
const output = 'app.js'
9-
1012
let newSource = ''
11-
input.forEach((name) => {
13+
this.input.forEach((name) => {
1214
newSource += `${compilation.assets[name].source()}\n`
1315
delete compilation.assets[name]
1416
})
1517

16-
compilation.assets[output] = {
18+
compilation.assets[this.output] = {
1719
source: () => newSource,
1820
size: () => newSource.length
1921
}

server/build/webpack.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ export default async function createCompiler (dir, { dev = false, quiet = false,
120120
}
121121
} else {
122122
plugins.push(
123-
new CombineAssetsPlugin(),
123+
new CombineAssetsPlugin({
124+
input: ['commons.js', 'main.js'],
125+
output: 'app.js'
126+
}),
124127
new webpack.optimize.UglifyJsPlugin({
125128
compress: { warnings: false },
126129
sourceMap: false

server/document.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ export class NextScript extends Component {
8080
)
8181
}
8282

83+
// In the production mode, we have a single asset
84+
// So, we can load the script with async
8385
return this.getChunkScript('app.js', { async: true })
8486
}
8587

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy