Skip to content

Commit

Permalink
fix(server): fix loading order of assets (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
ambar authored and gregberge committed Mar 13, 2019
1 parent e236d0a commit 4c8ae60
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 98 deletions.
1 change: 1 addition & 0 deletions examples/razzle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@reach/router": "^1.2.1",
"common-tags": "^1.8.0",
"express": "^4.16.2",
"normalize.css": "^8.0.1",
"razzle": "^3.0.0-alpha.0",
"react": "^16.0.0",
"react-dom": "^16.0.0"
Expand Down
14 changes: 13 additions & 1 deletion examples/razzle/razzle.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const LoadableBabelPlugin = require('@loadable/babel-plugin')
const babelPresetRazzle = require('razzle/babel')

module.exports = {
modify: (config, { target }) => {
modify: (config, { dev, target }) => {
const appConfig = Object.assign({}, config)

if (target === 'web') {
Expand All @@ -17,6 +17,18 @@ module.exports = {
writeToDisk: { filename },
}),
]

appConfig.output.filename = dev
? 'static/js/[name].js'
: 'static/js/[name].[chunkhash:8].js'

appConfig.optimization = Object.assign({}, appConfig.optimization, {
runtimeChunk: true,
splitChunks: {
chunks: 'all',
name: dev,
},
})
}

return appConfig
Expand Down
1 change: 1 addition & 0 deletions examples/razzle/src/client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'normalize.css'
import React from 'react'
import { hydrate } from 'react-dom'
import { loadableReady } from '@loadable/component'
Expand Down
5 changes: 5 additions & 0 deletions examples/razzle/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5944,6 +5944,11 @@ normalize-url@^3.0.0:
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-3.3.0.tgz#b2e1c4dc4f7c6d57743df733a4f5978d18650559"
integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==

normalize.css@^8.0.1:
version "8.0.1"
resolved "https://registry.yarnpkg.com/normalize.css/-/normalize.css-8.0.1.tgz#9b98a208738b9cc2634caacbc42d131c97487bf3"
integrity sha512-qizSNPO93t1YUuUhP22btGOo3chcvDFqFaj2TRybP0DMxkHOCTYwp3n34fel4a31ORXy4m1Xq0Gyqpb5m33qIg==

npm-bundled@^1.0.1:
version "1.0.5"
resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.0.5.tgz#3c1732b7ba936b3a10325aef616467c0ccbcc979"
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/ChunkExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class ChunkExtractor {
// Main assets

getMainAssets(scriptType) {
const chunks = [...this.chunks, ...this.entrypoints]
const chunks = [...this.entrypoints, ...this.chunks]
const assets = this.getChunkAssets(chunks)
if (scriptType) {
return assets.filter(asset => asset.scriptType === scriptType)
Expand Down Expand Up @@ -359,7 +359,7 @@ class ChunkExtractor {

getPreAssets() {
const mainAssets = this.getMainAssets()
const chunks = [...this.chunks, ...this.entrypoints]
const chunks = [...this.entrypoints, ...this.chunks]
const preloadAssets = this.getChunkChildAssets(chunks, 'preload')
const prefetchAssets = this.getChunkChildAssets(chunks, 'prefetch')
return [...mainAssets, ...preloadAssets, ...prefetchAssets]
Expand Down
Loading

0 comments on commit 4c8ae60

Please sign in to comment.