Skip to content

Commit

Permalink
fix: drop webpack version detector
Browse files Browse the repository at this point in the history
  • Loading branch information
kisenka committed Apr 12, 2020
1 parent 57ebe41 commit 7131578
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 28 deletions.
10 changes: 2 additions & 8 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const SVGCompiler = require('svg-baker');

const { NAMESPACE } = require('./config');
const configure = require('./configurator');
const { getWebpackVersion } = require('./utils');
const Exceptions = require('./exceptions');

let svgCompiler = new SVGCompiler();
Expand All @@ -31,13 +30,8 @@ module.exports = function loader(content) {

const configObj = { context: loaderContext };

if (getWebpackVersion.IS_4) {
configObj.config = loaderContext.query;
configObj.target = loaderContext.target;
} else {
configObj.config = matchedRules;
configObj.target = loaderContext.options.target || loaderContext.target;
}
configObj.config = matchedRules;
configObj.target = loaderContext.target;

/**
* @type {SVGSpriteLoaderConfig}
Expand Down
21 changes: 6 additions & 15 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ const {
MappedList,
replaceInModuleSource,
replaceSpritePlaceholder,
getWebpackVersion,
getMatchedRule
} = require('./utils');

const webpackVersion = parseInt(getWebpackVersion(), 10);

const defaultConfig = {
plainSprite: false,
spriteAttrs: {}
Expand Down Expand Up @@ -187,21 +184,15 @@ class SVGSpritePlugin {
chunks.forEach((chunk) => {
let modules;

switch (webpackVersion) {
case 4:
modules = Array.from(chunk.modulesIterable);
break;
case 3:
modules = chunk.mapModules();
break;
default:
({ modules } = chunk);
break;
if (chunk.modulesIterable) {
modules = Array.from(chunk.modulesIterable);
} else {
modules = chunk.modules;
}

modules
// dirty hack to identify modules extracted by extract-text-webpack-plugin
// TODO refactor
// dirty hack to identify modules extracted by extract-text-webpack-plugin
// TODO refactor
.filter(module => '_originalModule' in module)
.forEach(module => replaceInModuleSource(module, replacements));
});
Expand Down
6 changes: 2 additions & 4 deletions lib/utils/get-module-chunk.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const webpackVersion = require('./get-webpack-version');

/**
* Find nearest module chunk (not sure that is reliable method, but who cares).
* @see http://stackoverflow.com/questions/43202761/how-to-determine-all-module-chunks-in-webpack
Expand All @@ -10,9 +8,9 @@ const webpackVersion = require('./get-webpack-version');
function getModuleChunk(module, modules) {
let chunks;

if (webpackVersion.IS_4) {
if (module.chunksIterable) {
chunks = Array.from(module.chunksIterable);
} else if (parseInt(webpackVersion(), 10) >= 3) {
} else if (module.mapChunks) {
chunks = module.mapChunks();
} else {
chunks = module.chunks;
Expand Down
1 change: 0 additions & 1 deletion lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports.getAllModules = require('./get-all-modules');
// module.exports.getLoaderOptions = require('./get-loader-options');
module.exports.getModuleChunk = require('./get-module-chunk');
module.exports.getMatchedRule = require('./get-matched-rule');
module.exports.getWebpackVersion = require('./get-webpack-version');
module.exports.isModuleShouldBeExtracted = require('./is-module-should-be-extracted');
module.exports.interpolate = require('./interpolate');
module.exports.isWebpack1 = require('./is-webpack-1');
Expand Down

0 comments on commit 7131578

Please sign in to comment.