Skip to content

Commit 4c8ae60

Browse files
ambargregberge
authored andcommitted
fix(server): fix loading order of assets (#266)
1 parent e236d0a commit 4c8ae60

File tree

6 files changed

+117
-98
lines changed

6 files changed

+117
-98
lines changed

examples/razzle/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"@reach/router": "^1.2.1",
1414
"common-tags": "^1.8.0",
1515
"express": "^4.16.2",
16+
"normalize.css": "^8.0.1",
1617
"razzle": "^3.0.0-alpha.0",
1718
"react": "^16.0.0",
1819
"react-dom": "^16.0.0"

examples/razzle/razzle.config.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const LoadableBabelPlugin = require('@loadable/babel-plugin')
44
const babelPresetRazzle = require('razzle/babel')
55

66
module.exports = {
7-
modify: (config, { target }) => {
7+
modify: (config, { dev, target }) => {
88
const appConfig = Object.assign({}, config)
99

1010
if (target === 'web') {
@@ -17,6 +17,18 @@ module.exports = {
1717
writeToDisk: { filename },
1818
}),
1919
]
20+
21+
appConfig.output.filename = dev
22+
? 'static/js/[name].js'
23+
: 'static/js/[name].[chunkhash:8].js'
24+
25+
appConfig.optimization = Object.assign({}, appConfig.optimization, {
26+
runtimeChunk: true,
27+
splitChunks: {
28+
chunks: 'all',
29+
name: dev,
30+
},
31+
})
2032
}
2133

2234
return appConfig

examples/razzle/src/client.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'normalize.css'
12
import React from 'react'
23
import { hydrate } from 'react-dom'
34
import { loadableReady } from '@loadable/component'

examples/razzle/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5944,6 +5944,11 @@ normalize-url@^3.0.0:
59445944
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-3.3.0.tgz#b2e1c4dc4f7c6d57743df733a4f5978d18650559"
59455945
integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==
59465946

5947+
normalize.css@^8.0.1:
5948+
version "8.0.1"
5949+
resolved "https://registry.yarnpkg.com/normalize.css/-/normalize.css-8.0.1.tgz#9b98a208738b9cc2634caacbc42d131c97487bf3"
5950+
integrity sha512-qizSNPO93t1YUuUhP22btGOo3chcvDFqFaj2TRybP0DMxkHOCTYwp3n34fel4a31ORXy4m1Xq0Gyqpb5m33qIg==
5951+
59475952
npm-bundled@^1.0.1:
59485953
version "1.0.5"
59495954
resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.0.5.tgz#3c1732b7ba936b3a10325aef616467c0ccbcc979"

packages/server/src/ChunkExtractor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class ChunkExtractor {
293293
// Main assets
294294

295295
getMainAssets(scriptType) {
296-
const chunks = [...this.chunks, ...this.entrypoints]
296+
const chunks = [...this.entrypoints, ...this.chunks]
297297
const assets = this.getChunkAssets(chunks)
298298
if (scriptType) {
299299
return assets.filter(asset => asset.scriptType === scriptType)
@@ -359,7 +359,7 @@ class ChunkExtractor {
359359

360360
getPreAssets() {
361361
const mainAssets = this.getMainAssets()
362-
const chunks = [...this.chunks, ...this.entrypoints]
362+
const chunks = [...this.entrypoints, ...this.chunks]
363363
const preloadAssets = this.getChunkChildAssets(chunks, 'preload')
364364
const prefetchAssets = this.getChunkChildAssets(chunks, 'prefetch')
365365
return [...mainAssets, ...preloadAssets, ...prefetchAssets]

0 commit comments

Comments
 (0)