12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- const pluginCompat = require('./util/plugin-compat');
- const mixinCssDependency = function(CssDependency) {
- const Dependency = Object.getPrototypeOf(CssDependency.prototype).constructor;
- CssDependency.prototype.updateHash = function(hash) {
- Dependency.prototype.updateHash.call(this, hash);
- hash.update(this.content);
- };
- };
- class SupportMiniCssExtractPlugin {
- 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;
- mixinCssDependency(CssDependency);
- break;
- }
- }
- },
- );
- pluginCompat.tap(
- compiler,
- '_hardSourceFreezeDependency',
- 'HardMiniCssExtractPlugin freeze',
- (frozen, dependency, extra) => {
- if (dependency.constructor === CssDependency) {
- return {
- type: 'CssDependency',
- line: {
- identifier: dependency.identifier,
- content: dependency.content,
- media: dependency.media,
- sourceMap: dependency.sourceMap,
- },
- context: dependency.context,
- identifierIndex: dependency.identifierIndex,
- };
- }
- return frozen;
- },
- );
- pluginCompat.tap(
- compiler,
- '_hardSourceThawDependency',
- 'HardMiniCssExtractPlugin',
- (dependency, { type, line, context, identifierIndex }, extra) => {
- if (type === 'CssDependency') {
- return new CssDependency(line, context, identifierIndex);
- }
- return dependency;
- },
- );
- }
- }
- module.exports = SupportMiniCssExtractPlugin;
|