-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Images in css not emitted on subsequent builds when using mini-css-extract-plugin with non-persistent build #367
Comments
Sorry... I wrote up the issue with a reproduction but realised that it didn't match the exact problem. Updated with more info about specific cases where this can happen (when the build is not persisted). |
@OscarBarrett Thank you for opening this issue. I'm going to file a bug in mini-css for this. It is a bug in mini-css that it does not lift assets to the parent module. |
I'll see if I can implement #76 as a workaround. If you were to exclude |
Having the same problem, basic
On next run, when reading from cache fonts are not loaded... They are included in stylus file, loaded into webpack with file-loader... Editing file that includes it bring them back... |
Did some digging and it looks like that, As temporary workaround, wrote an plugin that will collect assets for that dependencies const hasCssLoader = (loaders = []) => loaders.find(l => l.loader.indexOf('css-loader') !== -1)
// This will collect assets from dependencies,
// use only with hard-source-webpack-plugin, to link assets in next run!
// Remove this after https://github.com/webpack-contrib/mini-css-extract-plugin/pull/177
export default class LinkCssAssetsToIssuerPlugin {
apply(compiler) {
let parentAssets = {}
const collect = module => {
if (module.issuer && hasCssLoader(module.issuer.loaders)) {
const bi = module.buildInfo
const hasAssets = bi && bi.assets && Object.keys(bi.assets).length > 0
if (hasAssets) {
const parent = module.issuer.resource
parentAssets = {
...parentAssets,
[parent]: { ...parentAssets[parent], ...bi.assets },
}
}
}
const assets = parentAssets[module.resource]
if (assets) {
module.buildInfo = module.buildInfo || { assets: {} }
module.buildInfo.assets = { ...module.buildInfo.assets, ...assets }
}
}
compiler.hooks.compilation.tap('LinkCssAssetsToIssuerPlugin', compilation => {
compilation.hooks.succeedModule.tap('LinkCssAssetsToIssuerPlugin succeedModule', collect)
compilation.hooks.failedModule.tap('LinkCssAssetsToIssuerPlugin failedModule', collect)
})
}
} save this as
|
Expected Behavior
When the webpack build is not persisted (e.g. when using something like clean-webpack-plugin, or webpack-dev-server with
contentBase
set tofalse
), images referenced in css files should be emitted on subsequent builds if they no longer exist on disk.Actual Behavior
When using mini-css-extract-plugin, images referenced in css files are not emitted on subsequent builds. With only css-loader they are.
Is an error being thrown?
No
Steps to Reproduce
Minimal reproduction here
Operating System, Node, and NPM dependency versions
The text was updated successfully, but these errors were encountered: