Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: compatibility with webpack@5
  • Loading branch information
alexander-akait committed Aug 26, 2020
commit 09c1de58ba7bc682455fbf8e62552aba39cfa99b
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @jest-environment node
*/

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

Expand Down
1 change: 1 addition & 0 deletions test/cases/cache/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './style.css';
3 changes: 3 additions & 0 deletions test/cases/cache/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background: red;
}
33 changes: 33 additions & 0 deletions test/cases/cache/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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',
}),
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background: red;
}