Skip to content

Commit 7a44b07

Browse files
tiendqevilebottnawi
authored andcommitted
refactor: replace literal plugin name in strings with const (#157)
1 parent 41347f7 commit 7a44b07

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class MiniCssExtractPlugin {
175175
chunk,
176176
contentHashType: NS,
177177
},
178-
identifier: `mini-css-extract-plugin.${chunk.id}`,
178+
identifier: `${pluginName}.${chunk.id}`,
179179
hash: chunk.contentHash[NS],
180180
});
181181
}
@@ -199,7 +199,7 @@ class MiniCssExtractPlugin {
199199
chunk,
200200
contentHashType: NS,
201201
},
202-
identifier: `mini-css-extract-plugin.${chunk.id}`,
202+
identifier: `${pluginName}.${chunk.id}`,
203203
hash: chunk.contentHash[NS],
204204
});
205205
}
@@ -312,7 +312,7 @@ class MiniCssExtractPlugin {
312312
return Template.asString([
313313
source,
314314
'',
315-
'// mini-css-extract-plugin CSS loading',
315+
`// ${pluginName} CSS loading`,
316316
`var cssChunks = ${JSON.stringify(chunkMap)};`,
317317
'if(installedCssChunks[chunkId]) promises.push(installedCssChunks[chunkId]);',
318318
'else if(installedCssChunks[chunkId] !== 0 && cssChunks[chunkId]) {',

src/loader.js

+18-22
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import SingleEntryPlugin from 'webpack/lib/SingleEntryPlugin';
1010
import LimitChunkCountPlugin from 'webpack/lib/optimize/LimitChunkCountPlugin';
1111

1212
const NS = path.dirname(fs.realpathSync(__filename));
13+
const pluginName = 'mini-css-extract-plugin';
1314

1415
const exec = (loaderContext, code, filename) => {
1516
const module = new NativeModule(filename, loaderContext);
@@ -42,25 +43,23 @@ export function pitch(request) {
4243
publicPath,
4344
};
4445
const childCompiler = this._compilation.createChildCompiler(
45-
`mini-css-extract-plugin ${request}`,
46+
`${pluginName} ${request}`,
4647
outputOptions
4748
);
4849
new NodeTemplatePlugin(outputOptions).apply(childCompiler);
4950
new LibraryTemplatePlugin(null, 'commonjs2').apply(childCompiler);
5051
new NodeTargetPlugin().apply(childCompiler);
51-
new SingleEntryPlugin(
52-
this.context,
53-
`!!${request}`,
54-
'mini-css-extract-plugin'
55-
).apply(childCompiler);
52+
new SingleEntryPlugin(this.context, `!!${request}`, pluginName).apply(
53+
childCompiler
54+
);
5655
new LimitChunkCountPlugin({ maxChunks: 1 }).apply(childCompiler);
5756
// We set loaderContext[NS] = false to indicate we already in
5857
// a child compiler so we don't spawn another child compilers from there.
5958
childCompiler.hooks.thisCompilation.tap(
60-
'mini-css-extract-plugin loader',
59+
`${pluginName} loader`,
6160
(compilation) => {
6261
compilation.hooks.normalModuleLoader.tap(
63-
'mini-css-extract-plugin loader',
62+
`${pluginName} loader`,
6463
(loaderContext, module) => {
6564
loaderContext[NS] = false; // eslint-disable-line no-param-reassign
6665
if (module.request === request) {
@@ -79,21 +78,18 @@ export function pitch(request) {
7978
);
8079

8180
let source;
82-
childCompiler.hooks.afterCompile.tap(
83-
'mini-css-extract-plugin',
84-
(compilation) => {
85-
source =
86-
compilation.assets[childFilename] &&
87-
compilation.assets[childFilename].source();
81+
childCompiler.hooks.afterCompile.tap(pluginName, (compilation) => {
82+
source =
83+
compilation.assets[childFilename] &&
84+
compilation.assets[childFilename].source();
8885

89-
// Remove all chunk assets
90-
compilation.chunks.forEach((chunk) => {
91-
chunk.files.forEach((file) => {
92-
delete compilation.assets[file]; // eslint-disable-line no-param-reassign
93-
});
86+
// Remove all chunk assets
87+
compilation.chunks.forEach((chunk) => {
88+
chunk.files.forEach((file) => {
89+
delete compilation.assets[file]; // eslint-disable-line no-param-reassign
9490
});
95-
}
96-
);
91+
});
92+
});
9793

9894
const callback = this.async();
9995
childCompiler.runAsChild((err, entries, compilation) => {
@@ -133,7 +129,7 @@ export function pitch(request) {
133129
} catch (e) {
134130
return callback(e);
135131
}
136-
let resultSource = '// extracted by mini-css-extract-plugin';
132+
let resultSource = `// extracted by ${pluginName}`;
137133
if (locals && typeof resultSource !== 'undefined') {
138134
resultSource += `\nmodule.exports = ${JSON.stringify(locals)};`;
139135
}

0 commit comments

Comments
 (0)