Skip to content

Commit 21832c7

Browse files
fix: compatibility with webpack@5 (#571)
1 parent 25b0ecd commit 21832c7

File tree

13 files changed

+51
-3
lines changed

13 files changed

+51
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ npm-debug.log*
55
/coverage
66
/dist
77
/test/js
8+
/test/outputs
89
/local
910
/reports
1011
/node_modules

src/index.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
/* eslint-disable class-methods-use-this */
22

33
import webpack from 'webpack';
4-
import sources from 'webpack-sources';
5-
64
import validateOptions from 'schema-utils';
75

86
import CssDependency from './CssDependency';
97
import schema from './plugin-options.json';
108

11-
const { ConcatSource, SourceMapSource, OriginalSource } = sources;
9+
// webpack 5 exposes the sources property to ensure the right version of webpack-sources is used
10+
const { ConcatSource, SourceMapSource, OriginalSource } =
11+
// eslint-disable-next-line global-require
12+
webpack.sources || require('webpack-sources');
13+
1214
const {
1315
Template,
1416
util: { createHash },

test/TestCases.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @jest-environment node
3+
*/
4+
15
import fs from 'fs';
26
import path from 'path';
37

test/cases/cache/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './style.css';

test/cases/cache/style.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background: red;
3+
}

test/cases/cache/webpack.config.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import path from 'path';
2+
3+
import del from 'del';
4+
5+
import Self from '../../../src';
6+
7+
const fileSystemCacheDirectory = path.resolve(
8+
__dirname,
9+
'../../outputs/cache/type-filesystem'
10+
);
11+
12+
del.sync(fileSystemCacheDirectory);
13+
14+
module.exports = {
15+
entry: './index.js',
16+
cache: {
17+
type: 'filesystem',
18+
cacheDirectory: fileSystemCacheDirectory,
19+
},
20+
module: {
21+
rules: [
22+
{
23+
test: /\.css$/,
24+
use: [Self.loader, 'css-loader'],
25+
},
26+
],
27+
},
28+
plugins: [
29+
new Self({
30+
filename: '[name].css',
31+
}),
32+
],
33+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
background: red;
3+
}
4+

0 commit comments

Comments
 (0)