Skip to content

Commit

Permalink
fix: compatibility with webpack@5 (#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Aug 26, 2020
1 parent 25b0ecd commit 21832c7
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,6 +5,7 @@ npm-debug.log*
/coverage
/dist
/test/js
/test/outputs
/local
/reports
/node_modules
Expand Down
8 changes: 5 additions & 3 deletions src/index.js
@@ -1,14 +1,16 @@
/* eslint-disable class-methods-use-this */

import webpack from 'webpack';
import sources from 'webpack-sources';

import validateOptions from 'schema-utils';

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

const { ConcatSource, SourceMapSource, OriginalSource } = sources;
// webpack 5 exposes the sources property to ensure the right version of webpack-sources is used
const { ConcatSource, SourceMapSource, OriginalSource } =
// eslint-disable-next-line global-require
webpack.sources || require('webpack-sources');

const {
Template,
util: { createHash },
Expand Down
4 changes: 4 additions & 0 deletions test/TestCases.test.js
@@ -1,3 +1,7 @@
/**
* @jest-environment node
*/

import fs from 'fs';
import path from 'path';

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions test/cases/cache/index.js
@@ -0,0 +1 @@
import './style.css';
3 changes: 3 additions & 0 deletions test/cases/cache/style.css
@@ -0,0 +1,3 @@
body {
background: red;
}
33 changes: 33 additions & 0 deletions test/cases/cache/webpack.config.js
@@ -0,0 +1,33 @@
import path from 'path';

import del from 'del';

import Self from '../../../src';

const fileSystemCacheDirectory = path.resolve(
__dirname,
'../../outputs/cache/type-filesystem'
);

del.sync(fileSystemCacheDirectory);

module.exports = {
entry: './index.js',
cache: {
type: 'filesystem',
cacheDirectory: fileSystemCacheDirectory,
},
module: {
rules: [
{
test: /\.css$/,
use: [Self.loader, 'css-loader'],
},
],
},
plugins: [
new Self({
filename: '[name].css',
}),
],
};
@@ -0,0 +1,4 @@
body {
background: red;
}

0 comments on commit 21832c7

Please sign in to comment.