Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
refactor: remove excessive constants
  • Loading branch information
goganchic committed Sep 13, 2019
commit 7e6fbf2c26ec1db79d64c859863b4dbf8e15dafe
41 changes: 11 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 23 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,29 +148,32 @@ class MiniCssExtractPlugin {

apply(compiler) {
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
compilation.hooks.normalModuleLoader.tap(pluginName, (lc, m) => {
const loaderContext = lc;
const module = m;

loaderContext[MODULE_TYPE] = (content) => {
if (!Array.isArray(content) && content != null) {
throw new Error(
`Exported value was not extracted as an array: ${JSON.stringify(
content
)}`
);
}
compilation.hooks.normalModuleLoader.tap(
pluginName,
(loaderContext, module) => {
// eslint-disable-next-line no-param-reassign
loaderContext[MODULE_TYPE] = (content) => {
if (!Array.isArray(content) && content != null) {
throw new Error(
`Exported value was not extracted as an array: ${JSON.stringify(
content
)}`
);
}

const identifierCountMap = new Map();
const identifierCountMap = new Map();

for (const line of content) {
const count = identifierCountMap.get(line.identifier) || 0;
for (const line of content) {
const count = identifierCountMap.get(line.identifier) || 0;

module.addDependency(new CssDependency(line, m.context, count));
identifierCountMap.set(line.identifier, count + 1);
}
};
});
module.addDependency(
new CssDependency(line, module.context, count)
);
identifierCountMap.set(line.identifier, count + 1);
}
};
}
);

compilation.dependencyFactories.set(
CssDependency,
Expand Down