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
80 changes: 40 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[![chat][chat]][chat-url]
[![size][size]][size-url]

# cssnano-webpack-plugin
# css-minimizer-webpack-plugin

This plugin uses [cssnano](https://cssnano.co) to optimize and minify your CSS.

Expand All @@ -24,18 +24,18 @@ Works with Webpack 4+.

## Getting Started

To begin, you'll need to install `cssnano-webpack-plugin`:
To begin, you'll need to install `css-minimizer-webpack-plugin`:

```console
$ npm install cssnano-webpack-plugin --save-dev
$ npm install css-minimizer-webpack-plugin --save-dev
```

Then add the plugin to your `webpack` configuration. For example:

**webpack.config.js**

```js
const CssnanoPlugin = require('cssnano-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');

module.exports = {
module: {
Expand All @@ -48,7 +48,7 @@ module.exports = {
},
optimization: {
minimize: true,
minimizer: [new CssnanoPlugin()],
minimizer: [new CssMinimizerPlugin()],
},
};
```
Expand All @@ -69,7 +69,7 @@ module.exports = {
optimization: {
minimize: true,
minimizer: [
new CssnanoPlugin({
new CssMinimizerPlugin({
test: /\.foo\.css$/i,
}),
],
Expand All @@ -91,7 +91,7 @@ module.exports = {
optimization: {
minimize: true,
minimizer: [
new CssnanoPlugin({
new CssMinimizerPlugin({
include: /\/includes/,
}),
],
Expand All @@ -113,7 +113,7 @@ module.exports = {
optimization: {
minimize: true,
minimizer: [
new CssnanoPlugin({
new CssMinimizerPlugin({
exclude: /\/excludes/,
}),
],
Expand All @@ -129,7 +129,7 @@ Type: `Boolean|String`
Default: `true`

Enable file caching.
Default path to cache directory: `node_modules/.cache/cssnano-webpack-plugin`.
Default path to cache directory: `node_modules/.cache/css-minimizer-webpack-plugin`.

> ℹ️ If you use your own `minify` function please read the `minify` section for cache invalidation correctly.

Expand All @@ -144,7 +144,7 @@ module.exports = {
optimization: {
minimize: true,
minimizer: [
new CssnanoPlugin({
new CssMinimizerPlugin({
cache: true,
}),
],
Expand All @@ -163,7 +163,7 @@ module.exports = {
optimization: {
minimize: true,
minimizer: [
new CssnanoPlugin({
new CssMinimizerPlugin({
cache: 'path/to/cache',
}),
],
Expand All @@ -184,9 +184,9 @@ Default cache keys:

```js
({
cssnano: require('cssnano/package.json').version, // cssnano version
'cssnano-webpack-plugin': require('../package.json').version, // plugin version
'cssnano-webpack-plugin-options': this.options, // plugin options
cssMinimizer: require('cssnano/package.json').version, // cssnano version
'css-minimizer-webpack-plugin': require('../package.json').version, // plugin version
'css-minimizer-webpack-plugin-options': this.options, // plugin options
path: compiler.outputPath ? `${compiler.outputPath}/${file}` : file, // asset path
hash: crypto.createHash('md4').update(input).digest('hex'), // source file hash
});
Expand All @@ -199,7 +199,7 @@ module.exports = {
optimization: {
minimize: true,
minimizer: [
new CssnanoPlugin({
new CssMinimizerPlugin({
cache: true,
cacheKeys: (defaultCacheKeys, file) => {
defaultCacheKeys.myCacheKey = 'myCacheKeyValue';
Expand Down Expand Up @@ -233,7 +233,7 @@ module.exports = {
optimization: {
minimize: true,
minimizer: [
new CssnanoPlugin({
new CssMinimizerPlugin({
parallel: true,
}),
],
Expand All @@ -252,7 +252,7 @@ module.exports = {
optimization: {
minimize: true,
minimizer: [
new CssnanoPlugin({
new CssMinimizerPlugin({
parallel: 4,
}),
],
Expand Down Expand Up @@ -289,7 +289,7 @@ module.exports = {
optimization: {
minimize: true,
minimizer: [
new CssnanoPlugin({
new CssMinimizerPlugin({
sourceMap: true,
}),
],
Expand All @@ -315,10 +315,10 @@ module.exports = {
optimization: {
minimize: true,
minimizer: [
new CssnanoPlugin({
new CssMinimizerPlugin({
minify: (data) => {
const postcss = require('postcss');
const { input, postcssOptions, cssnanoOptions } = data;
const { input, postcssOptions, minimizerOptions } = data;

const plugin = postcss.plugin(
'custom-plugin',
Expand All @@ -344,7 +344,7 @@ module.exports = {
};
```

### `cssnanoOptions`
### `minimizerOptions`

Type: `Object`
Default: `{ preset: 'default' }`
Expand All @@ -356,8 +356,8 @@ module.exports = {
optimization: {
minimize: true,
minimizer: [
new CssnanoPlugin({
cssnanoOptions: {
new CssMinimizerPlugin({
minimizerOptions: {
preset: [
'default',
{
Expand All @@ -376,7 +376,7 @@ module.exports = {
Type: `Function<(warning, file, source) -> Boolean>`
Default: `() => true`

Allow to filter [cssnano](https://github.com/cssnano/cssnano) warnings.
Allow to filter css-minimizer warnings (By default [cssnano](https://github.com/cssnano/cssnano)).
Return `true` to keep the warning, a falsy value (`false`/`null`/`undefined`) otherwise.

> ⚠️ The `source` argument will contain `undefined` if you don't use source maps.
Expand All @@ -388,7 +388,7 @@ module.exports = {
optimization: {
minimize: true,
minimizer: [
new CssnanoPlugin({
new CssMinimizerPlugin({
warningsFilter: (warning, file, source) => {
if (/Dropping unreachable code/i.test(warning)) {
return true;
Expand Down Expand Up @@ -417,7 +417,7 @@ module.exports = {
Don't forget to enable `sourceMap` options for all loaders.

```js
const CssnanoPlugin = require('cssnano-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');

module.exports = {
module: {
Expand All @@ -434,7 +434,7 @@ module.exports = {
},
optimization: {
minimizer: [
new CssnanoPlugin({
new CssMinimizerPlugin({
sourceMap: true,
}),
],
Expand All @@ -450,8 +450,8 @@ Remove all comments (including comments starting with `/*!`).
module.exports = {
optimization: {
minimizer: [
new CssnanoPlugin({
cssnanoOptions: {
new CssMinimizerPlugin({
minimizerOptions: {
preset: [
'default',
{
Expand All @@ -475,17 +475,17 @@ Please take a moment to read our contributing guidelines if you haven't yet done

[MIT](./LICENSE)

[npm]: https://img.shields.io/npm/v/cssnano-webpack-plugin.svg
[npm-url]: https://npmjs.com/package/cssnano-webpack-plugin
[node]: https://img.shields.io/node/v/cssnano-webpack-plugin.svg
[npm]: https://img.shields.io/npm/v/css-minimizer-webpack-plugin.svg
[npm-url]: https://npmjs.com/package/css-minimizer-webpack-plugin
[node]: https://img.shields.io/node/v/css-minimizer-webpack-plugin.svg
[node-url]: https://nodejs.org
[deps]: https://david-dm.org/webpack-contrib/cssnano-webpack-plugin.svg
[deps-url]: https://david-dm.org/webpack-contrib/cssnano-webpack-plugin
[tests]: https://github.com/webpack-contrib/cssnano-webpack-plugin/workflows/cssnano-webpack-plugin/badge.svg
[tests-url]: https://github.com/webpack-contrib/cssnano-webpack-plugin/actions
[cover]: https://codecov.io/gh/webpack-contrib/cssnano-webpack-plugin/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack-contrib/cssnano-webpack-plugin
[deps]: https://david-dm.org/webpack-contrib/css-minimizer-webpack-plugin.svg
[deps-url]: https://david-dm.org/webpack-contrib/css-minimizer-webpack-plugin
[tests]: https://github.com/webpack-contrib/css-minimizer-webpack-plugin/workflows/css-minimizer-webpack-plugin/badge.svg
[tests-url]: https://github.com/webpack-contrib/css-minimizer-webpack-plugin/actions
[cover]: https://codecov.io/gh/webpack-contrib/css-minimizer-webpack-plugin/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack-contrib/css-minimizer-webpack-plugin
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
[chat-url]: https://gitter.im/webpack/webpack
[size]: https://packagephobia.now.sh/badge?p=cssnano-webpack-plugin
[size-url]: https://packagephobia.now.sh/result?p=cssnano-webpack-plugin
[size]: https://packagephobia.now.sh/badge?p=css-minimizer-webpack-plugin
[size-url]: https://packagephobia.now.sh/result?p=css-minimizer-webpack-plugin
4 changes: 3 additions & 1 deletion src/Webpack4Cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export default class Webpack4Cache {
}

static getCacheDirectory() {
return findCacheDir({ name: 'cssnano-webpack-plugin' }) || os.tmpdir();
return (
findCacheDir({ name: 'css-minimizer-webpack-plugin' }) || os.tmpdir()
);
}

isEnabled() {
Expand Down
2 changes: 1 addition & 1 deletion src/Webpack5Cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class Cache {
const digest = hash.digest(hashDigest);
const cacheKeys = digest.substr(0, hashDigestLength);

return `${this.compilation.compilerPath}/CssnanoWebpackPlugin/${cacheKeys}/${task.file}`;
return `${this.compilation.compilerPath}/CssMinimizerWebpackPlugin/${cacheKeys}/${task.file}`;
}

get(task) {
Expand Down
Loading