Skip to content

Commit

Permalink
fix: improved webpack version check (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito authored Oct 23, 2020
1 parent bd7e0ba commit 60c3eef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable class-methods-use-this */

import webpack, { version as webpackVersion } from 'webpack';
import webpack from 'webpack';

import { validate } from 'schema-utils';

Expand Down Expand Up @@ -103,7 +103,9 @@ class MiniCssExtractPlugin {

/** @param {import("webpack").Compiler} compiler */
apply(compiler) {
const isWebpack4 = compiler.webpack ? false : webpackVersion[0] === '4';
const isWebpack4 = compiler.webpack
? false
: typeof compiler.resolvers !== 'undefined';

if (!isWebpack4) {
const { splitChunks } = compiler.options.optimization;
Expand Down
5 changes: 3 additions & 2 deletions src/loader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import path from 'path';

import loaderUtils from 'loader-utils';
import { version as webpackVersion } from 'webpack';
import NodeTemplatePlugin from 'webpack/lib/node/NodeTemplatePlugin';
import NodeTargetPlugin from 'webpack/lib/node/NodeTargetPlugin';
import LibraryTemplatePlugin from 'webpack/lib/LibraryTemplatePlugin';
Expand Down Expand Up @@ -103,7 +102,9 @@ export function pitch(request) {

let source;

const isWebpack4 = childCompiler.webpack ? false : webpackVersion[0] === '4';
const isWebpack4 = childCompiler.webpack
? false
: typeof childCompiler.resolvers !== 'undefined';

if (isWebpack4) {
childCompiler.hooks.afterCompile.tap(pluginName, (compilation) => {
Expand Down

0 comments on commit 60c3eef

Please sign in to comment.