Skip to content

Commit 5adabf2

Browse files
committed
optimize source code
1 parent bc488b1 commit 5adabf2

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const { Template } = webpack;
88

99
const NS = path.dirname(fs.realpathSync(__filename));
1010

11+
const pluginName = 'mini-css-extract-plugin';
12+
1113
class CssDependency extends webpack.Dependency {
1214
constructor({ identifier, content, media, sourceMap }, context, identifierIndex) {
1315
super();
@@ -93,8 +95,8 @@ class MiniCssExtractPlugin {
9395
}
9496

9597
apply(compiler) {
96-
compiler.hooks.thisCompilation.tap('mini-css-extract-plugin', (compilation) => {
97-
compilation.hooks.normalModuleLoader.tap('mini-css-extract-plugin', (lc, m) => {
98+
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
99+
compilation.hooks.normalModuleLoader.tap(pluginName, (lc, m) => {
98100
const loaderContext = lc;
99101
const module = m;
100102
loaderContext[NS] = (content) => {
@@ -111,7 +113,7 @@ class MiniCssExtractPlugin {
111113
});
112114
compilation.dependencyFactories.set(CssDependency, new CssModuleFactory());
113115
compilation.dependencyTemplates.set(CssDependency, new CssDependencyTemplate());
114-
compilation.mainTemplate.hooks.renderManifest.tap('mini-css-extract-plugin', (result, { chunk }) => {
116+
compilation.mainTemplate.hooks.renderManifest.tap(pluginName, (result, { chunk }) => {
115117
const renderedModules = Array.from(chunk.modulesIterable).filter(module => module.type === NS);
116118
if (renderedModules.length > 0) {
117119
result.push({
@@ -124,7 +126,7 @@ class MiniCssExtractPlugin {
124126
});
125127
}
126128
});
127-
compilation.chunkTemplate.hooks.renderManifest.tap('mini-css-extract-plugin', (result, { chunk }) => {
129+
compilation.chunkTemplate.hooks.renderManifest.tap(pluginName, (result, { chunk }) => {
128130
const renderedModules = Array.from(chunk.modulesIterable).filter(module => module.type === NS);
129131
if (renderedModules.length > 0) {
130132
result.push({
@@ -139,7 +141,7 @@ class MiniCssExtractPlugin {
139141
});
140142
const { mainTemplate } = compilation;
141143
mainTemplate.hooks.localVars.tap(
142-
'mini-css-extract-plugin',
144+
pluginName,
143145
(source, chunk) => {
144146
const chunkMap = this.getCssChunkObject(chunk);
145147
if (Object.keys(chunkMap).length > 0) {
@@ -158,7 +160,7 @@ class MiniCssExtractPlugin {
158160
},
159161
);
160162
mainTemplate.hooks.requireEnsure.tap(
161-
'mini-css-extract-plugin',
163+
pluginName,
162164
(source, chunk, hash) => {
163165
const chunkMap = this.getCssChunkObject(chunk);
164166
if (Object.keys(chunkMap).length > 0) {

0 commit comments

Comments
 (0)