Skip to content

Commit

Permalink
fix: deal with deprecation warnings from webpack 3
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #173
  • Loading branch information
kisenka committed Aug 18, 2017
1 parent aa334d2 commit d150035
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ const Chunk = require('webpack/lib/Chunk');
const SVGCompiler = require('svg-baker');
const Sprite = require('svg-baker/lib/sprite');
const { NAMESPACE } = require('./config');
const { MappedList, replaceInModuleSource, replaceSpritePlaceholder } = require('./utils');
const {
MappedList,
replaceInModuleSource,
replaceSpritePlaceholder,
getWebpackVersion
} = require('./utils');

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

class SVGSpritePlugin {
constructor() {
Expand Down Expand Up @@ -44,7 +51,9 @@ class SVGSpritePlugin {
const replacements = map.groupItemsBySymbolFile((acc, item) => acc[item.resource] = item.useUrl);

chunks.forEach((chunk) => {
chunk.modules
const modules = webpackVersion < 3 ? chunk.modules : chunk.mapModules();

modules
// dirty hack to identify modules extracted by extract-text-webpack-plugin
// TODO refactor
.filter(module => '_originalModule' in module)
Expand Down
10 changes: 9 additions & 1 deletion lib/utils/get-module-chunk.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
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 @@ -6,7 +8,13 @@
* @return {Chunk|null}
*/
function getModuleChunk(module, modules) {
const { chunks } = module;
let chunks;

if (parseInt(webpackVersion(), 10) >= 3) {
chunks = module.mapChunks();
} else {
chunks = module.chunks;
}

// webpack 1 compat
const issuer = typeof module.issuer === 'string'
Expand Down

0 comments on commit d150035

Please sign in to comment.