Skip to content

Commit 9f501cb

Browse files
authored
Merge pull request #5 from laibao101/feature/webpack5
feat: 通过特征来判断webpack5,修复语法错误
2 parents d97dd50 + a71f57b commit 9f501cb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ const path = require('path')
99
const { RawSource } = require('webpack-sources')
1010
const loaderUtils = require('loader-utils')
1111
const cssReplace = require('./css-replace')
12-
const webpack = require('webpack')
1312

14-
const webpackMajorVersion = Number(webpack.version.split('.')[0])
1513
const isCSS = (name) => /\.css$/.test(name)
1614
// const strip = (str) => str.replace(/\/$/, '')
1715

@@ -66,9 +64,11 @@ class CssUrlRelativePlugin {
6664
}
6765

6866
applyCompilation = (compilation) => {
67+
// webpack5 新加的 hook
68+
const isWebpack5 = compilation.hooks.processAssets !== undefined
6969
// webpack version <= 4
70-
if (webpackMajorVersion <= 4) {
71-
compilation.hooks.optimizeChunkAssets.tapAsync(plugin, (chunks, done) => {
70+
if (!isWebpack5) {
71+
compilation.hooks.optimizeChunkAssets.tapAsync(this.plugin, (chunks, done) => {
7272
this.fixCssUrl(compilation, chunks, done)
7373
})
7474
return;

0 commit comments

Comments
 (0)