-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: exclude mini-css loader modules (#382)
* fix: exclude mini-css loader modules mini-css does not emit assets when built from webpack's memory cache or hard-source's disk cache. Exclude the modules that lead to the child compilations that emit the assets so the assets are always emitted. This has a minor performance change instead of a large performance hit because the bulk of the css work is still cached outside of these excluded modules. * fix: text copy-webpack-plugin * fixup! fix: exclude mini-css loader modules * fixup! fix: exclude mini-css loader modules * fix: disable hard modules mini css test
- Loading branch information
Showing
12 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const pluginCompat = require('./util/plugin-compat'); | ||
|
||
/** | ||
* Exclude modules with CssDependency. These modules are what mini-css keys | ||
* child compilations on. Excluding them the child compilations and their | ||
* assets are built every build. This has a minor performance cost as the bulk | ||
* of the work for css is still cached. | ||
*/ | ||
class ExcludeMiniCssModulePlugin { | ||
apply(compiler) { | ||
let CssDependency; | ||
|
||
pluginCompat.tap( | ||
compiler, | ||
'make', | ||
'SupportMiniCssExtractPlugin', | ||
({ dependencyFactories }) => { | ||
const Dependencies = dependencyFactories.keys(); | ||
for (const Dep of Dependencies) { | ||
if (Dep.name === 'CssDependency') { | ||
CssDependency = Dep; | ||
break; | ||
} | ||
} | ||
}, | ||
); | ||
|
||
pluginCompat.tap( | ||
compiler, | ||
'_hardSourceAfterFreezeModule', | ||
'HardMiniCssExtractPlugin', | ||
(frozen, module, extra) => { | ||
if ( | ||
CssDependency && | ||
module.dependencies.some(dep => dep instanceof CssDependency) | ||
) { | ||
return null; | ||
} | ||
return frozen; | ||
}, | ||
); | ||
} | ||
} | ||
|
||
module.exports = ExcludeMiniCssModulePlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
var HardSourceWebpackPlugin = require('../../..'); | ||
|
||
var CopyWebpackPlugin = require('copy-webpack-plugin'); | ||
|
||
module.exports = { | ||
context: __dirname, | ||
entry: './index.js', | ||
output: { | ||
path: __dirname + '/tmp', | ||
filename: 'main.js', | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.png$/, | ||
loader: 'file-loader', | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
new HardSourceWebpackPlugin({ | ||
cacheDirectory: 'cache', | ||
}), | ||
new CopyWebpackPlugin(['images']), | ||
], | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.hello { | ||
color: blue; | ||
background: url('image.png'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('./index.css'); |
38 changes: 38 additions & 0 deletions
38
tests/fixtures/plugin-mini-css-extract-file/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var MiniCssExtractPlugin = require('mini-css-extract-plugin'); | ||
|
||
var HardSourceWebpackPlugin = require('../../..'); | ||
|
||
module.exports = { | ||
context: __dirname, | ||
entry: './index.js', | ||
output: { | ||
path: __dirname + '/tmp', | ||
filename: 'main.js', | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: [ | ||
MiniCssExtractPlugin.loader, | ||
'css-loader' | ||
] | ||
}, | ||
{ | ||
test: /\.png$/, | ||
use: [ | ||
'file-loader' | ||
] | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new MiniCssExtractPlugin(), | ||
new HardSourceWebpackPlugin({ | ||
cacheDirectory: 'cache', | ||
environmentHash: { | ||
root: __dirname + '/../../..', | ||
}, | ||
}), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters