Skip to content

Commit 8e5db60

Browse files
refactor: drop webpack v4
BREAKING CHANGE: drop webpack@4 from support, removed the cache option, removed the cacheKeys option, removed the sourceMap option, respect the devtool option by default
1 parent ee53e72 commit 8e5db60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1476
-5795
lines changed

.eslintrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
module.exports = {
22
root: true,
33
extends: ['@webpack-contrib/eslint-config-webpack', 'prettier'],
4+
rules: {
5+
'import/no-namespace': 'off',
6+
},
47
};

.github/workflows/nodejs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
matrix:
5757
os: [ubuntu-latest, windows-latest, macos-latest]
5858
node-version: [10.x, 12.x, 14.x]
59-
webpack-version: [4, latest]
59+
webpack-version: [latest]
6060

6161
runs-on: ${{ matrix.os }}
6262

.husky/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

.husky/commit-msg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx commitlint --edit $1

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx lint-staged

README.md

+15-133
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ If you want to run it also in development set the `optimization.minimize` option
5959

6060
And run `webpack` via your preferred method.
6161

62+
## Note about source maps
63+
64+
**Works only with `source-map`, `inline-source-map`, `hidden-source-map` and `nosources-source-map` values for the [`devtool`](https://webpack.js.org/configuration/devtool/) option.**
65+
66+
Why? Because CSS support only these source map types.
67+
68+
The plugin respect the [`devtool`](https://webpack.js.org/configuration/devtool/) and using the `SourceMapDevToolPlugin` plugin.
69+
Using supported `devtool` values enable source map generation.
70+
Using `SourceMapDevToolPlugin` with enabled the `columns` option enables source map generation.
71+
72+
Use source maps to map error message locations to modules (this slows down the compilation).
73+
If you use your own `minify` function please read the `minify` section for handling source maps correctly.
74+
6275
## Options
6376

6477
### `test`
@@ -124,97 +137,6 @@ module.exports = {
124137
};
125138
```
126139

127-
### `cache`
128-
129-
> ⚠ Ignored in webpack 5! Please use https://webpack.js.org/configuration/other-options/#cache.
130-
131-
Type: `Boolean|String`
132-
Default: `true`
133-
134-
Enable file caching.
135-
Default path to cache directory: `node_modules/.cache/css-minimizer-webpack-plugin`.
136-
137-
> ℹ️ If you use your own `minify` function please read the `minify` section for cache invalidation correctly.
138-
139-
#### `Boolean`
140-
141-
Enable/disable file caching.
142-
143-
**webpack.config.js**
144-
145-
```js
146-
module.exports = {
147-
optimization: {
148-
minimize: true,
149-
minimizer: [
150-
new CssMinimizerPlugin({
151-
cache: true,
152-
}),
153-
],
154-
},
155-
};
156-
```
157-
158-
#### `String`
159-
160-
Enable file caching and set path to cache directory.
161-
162-
**webpack.config.js**
163-
164-
```js
165-
module.exports = {
166-
optimization: {
167-
minimize: true,
168-
minimizer: [
169-
new CssMinimizerPlugin({
170-
cache: 'path/to/cache',
171-
}),
172-
],
173-
},
174-
};
175-
```
176-
177-
### `cacheKeys`
178-
179-
> ⚠ Ignored in webpack 5! Please use https://webpack.js.org/configuration/other-options/#cache.
180-
181-
Type: `Function<(defaultCacheKeys, file) -> Object>`
182-
Default: `defaultCacheKeys => defaultCacheKeys`
183-
184-
Allows you to override default cache keys.
185-
186-
Default cache keys:
187-
188-
```js
189-
({
190-
cssMinimizer: require('cssnano/package.json').version, // cssnano version
191-
'css-minimizer-webpack-plugin': require('../package.json').version, // plugin version
192-
'css-minimizer-webpack-plugin-options': this.options, // plugin options
193-
path: compiler.outputPath ? `${compiler.outputPath}/${file}` : file, // asset path
194-
hash: crypto.createHash('md4').update(input).digest('hex'), // source file hash
195-
});
196-
```
197-
198-
**webpack.config.js**
199-
200-
```js
201-
module.exports = {
202-
optimization: {
203-
minimize: true,
204-
minimizer: [
205-
new CssMinimizerPlugin({
206-
cache: true,
207-
cacheKeys: (defaultCacheKeys, file) => {
208-
defaultCacheKeys.myCacheKey = 'myCacheKeyValue';
209-
210-
return defaultCacheKeys;
211-
},
212-
}),
213-
],
214-
},
215-
};
216-
```
217-
218140
### `parallel`
219141

220142
Type: `Boolean|Number`
@@ -263,40 +185,6 @@ module.exports = {
263185
};
264186
```
265187

266-
### `sourceMap`
267-
268-
Type: `Boolean|Object`
269-
Default: `false` (see below for details around `devtool` value and `SourceMapDevToolPlugin` plugin)
270-
271-
Enable (and configure) source map support. Use [PostCss SourceMap options](https://github.com/postcss/postcss-loader#sourcemap).
272-
Default configuration when enabled: `{ inline: false }`.
273-
274-
**Works only with `source-map`, `inline-source-map`, `hidden-source-map` and `nosources-source-map` values for the [`devtool`](https://webpack.js.org/configuration/devtool/) option.**
275-
276-
Why? Because CSS support only these source map types.
277-
278-
The plugin respect the [`devtool`](https://webpack.js.org/configuration/devtool/) and using the `SourceMapDevToolPlugin` plugin.
279-
Using supported `devtool` values enable source map generation.
280-
Using `SourceMapDevToolPlugin` with enabled the `columns` option enables source map generation.
281-
282-
Use source maps to map error message locations to modules (this slows down the compilation).
283-
If you use your own `minify` function please read the `minify` section for handling source maps correctly.
284-
285-
**webpack.config.js**
286-
287-
```js
288-
module.exports = {
289-
optimization: {
290-
minimize: true,
291-
minimizer: [
292-
new CssMinimizerPlugin({
293-
sourceMap: true,
294-
}),
295-
],
296-
},
297-
};
298-
```
299-
300188
### `minify`
301189

302190
Type: `Function`
@@ -316,7 +204,6 @@ module.exports = {
316204
minimize: true,
317205
minimizer: [
318206
new CssMinimizerPlugin({
319-
sourceMap: true,
320207
minify: (data, inputMap, minimizerOptions) => {
321208
const postcss = require('postcss');
322209

@@ -476,6 +363,7 @@ Don't forget to enable `sourceMap` options for all loaders.
476363
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
477364

478365
module.exports = {
366+
devtool: 'source-map',
479367
module: {
480368
loaders: [
481369
{
@@ -489,11 +377,7 @@ module.exports = {
489377
],
490378
},
491379
optimization: {
492-
minimizer: [
493-
new CssMinimizerPlugin({
494-
sourceMap: true,
495-
}),
496-
],
380+
minimizer: [new CssMinimizerPlugin()],
497381
},
498382
};
499383
```
@@ -537,7 +421,6 @@ module.exports = {
537421
minimize: true,
538422
minimizer: [
539423
new CssMinimizerPlugin({
540-
sourceMap: true,
541424
minify: async (data, inputMap) => {
542425
const csso = require('csso');
543426
const sourcemap = require('source-map');
@@ -582,7 +465,6 @@ module.exports = {
582465
minimize: true,
583466
minimizer: [
584467
new CssMinimizerPlugin({
585-
sourceMap: true,
586468
minify: async (data, inputMap) => {
587469
// eslint-disable-next-line global-require
588470
const CleanCSS = require('clean-css');

husky.config.js

-6
This file was deleted.

jest.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
module.exports = {
22
testEnvironment: 'node',
3-
snapshotResolver: './test/helpers/snapshotResolver.js',
43
setupFilesAfterEnv: ['<rootDir>/setupTest.js'],
54
};

0 commit comments

Comments
 (0)