Update asset utils
This commit is contained in:
@ -32,7 +32,7 @@ const createBundle = (webpackStats) => {
|
||||
}
|
||||
|
||||
/**
|
||||
* An express middleware that sets req.assets from the build
|
||||
* An express middleware that sets req.bundle from the build
|
||||
* info in the given stats file. Should be used in production.
|
||||
*/
|
||||
export const staticAssets = (webpackStatsFile) => {
|
||||
@ -48,33 +48,33 @@ export const staticAssets = (webpackStatsFile) => {
|
||||
)
|
||||
}
|
||||
|
||||
const assets = createBundle(stats)
|
||||
const bundle = createBundle(stats)
|
||||
|
||||
return (req, res, next) => {
|
||||
req.assets = assets
|
||||
req.bundle = bundle
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An express middleware that sets req.assets from the
|
||||
* An express middleware that sets req.bundle from the
|
||||
* latest result from a running webpack compiler (i.e. using
|
||||
* webpack-dev-middleware). Should only be used in dev.
|
||||
*/
|
||||
export const assetsCompiler = (webpackCompiler) => {
|
||||
let assets
|
||||
export const devAssets = (webpackCompiler) => {
|
||||
let bundle
|
||||
webpackCompiler.plugin('done', (stats) => {
|
||||
assets = createBundle(stats.toJson())
|
||||
bundle = createBundle(stats.toJson())
|
||||
})
|
||||
|
||||
return (req, res, next) => {
|
||||
invariant(
|
||||
assets != null,
|
||||
'assetsCompiler middleware needs a running compiler; ' +
|
||||
'use webpack-dev-middleware in front of assetsCompiler'
|
||||
bundle != null,
|
||||
'devAssets middleware needs a running compiler; ' +
|
||||
'use webpack-dev-middleware in front of devAssets'
|
||||
)
|
||||
|
||||
req.assets = assets
|
||||
req.bundle = bundle
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user