Skip to content

Commit 3065917

Browse files
committed
Initial commit
0 parents  commit 3065917

31 files changed

+9394
-0
lines changed

.eslintrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 2018,
4+
"sourceType": "module",
5+
"ecmaFeatures": {
6+
"experimentalObjectRestSpread": true
7+
}
8+
},
9+
"env": {
10+
"node": true,
11+
"es6": true,
12+
"jest": true
13+
},
14+
"extends": ["eslint:recommended"]
15+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
coverage
3+
.vscode

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage
2+
node_modules
3+
test/fixtures

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "none"
4+
}

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: node_js
2+
node_js:
3+
- "node"

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## 1.0.0 - 2019-09-01
8+
9+
Initial release

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Loann Neveu
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# cssnano-webpack-plugin
2+
3+
This plugin uses [cssnano](https://cssnano.co) to optimize and minify your CSS.
4+
5+
Fully integrated in Webpack ecosystem: based on compiler hooks, respecting default Webpack output sources and compatible with other plugins like *SourceMapDevToolPlugin* or *webpack-subresource-integrity*.
6+
7+
Just like [optimize-css-assets-webpack-plugin](https://github.com/NMFR/optimize-css-assets-webpack-plugin) but more accurate with source maps and assets using query string.
8+
9+
Works with Webpack 4+.
10+
11+
## Getting Started
12+
13+
First, install `cssnano-webpack-plugin`:
14+
15+
```console
16+
$ npm install cssnano-webpack-plugin --save-dev
17+
```
18+
19+
Then add the plugin to your `webpack` configuration. For example:
20+
21+
**webpack.config.js**
22+
23+
```js
24+
const CssnanoPlugin = require('cssnano-webpack-plugin');
25+
26+
module.exports = {
27+
module: {
28+
loaders: [
29+
{
30+
test: /.s?css$/,
31+
use: [
32+
MiniCssExtractPlugin.loader,
33+
'css-loader',
34+
'sass-loader'
35+
]
36+
}
37+
]
38+
},
39+
optimization: {
40+
minimizer: [
41+
new CssnanoPlugin()
42+
]
43+
}
44+
};
45+
```
46+
47+
This will enable CSS optimization only in production mode. If you want to run it also in development, put the plugin configuration in the `plugins` option array.
48+
49+
## Options
50+
51+
### `test`
52+
53+
Type: `String|RegExp|Array<String|RegExp>` - default: `/\.css(\?.*)?$/i`
54+
55+
Test to match files against.
56+
57+
```js
58+
module.exports = {
59+
optimization: {
60+
minimizer: [
61+
new CssnanoPlugin({
62+
test: /\.foo\.css$/i
63+
})
64+
]
65+
}
66+
};
67+
```
68+
69+
`include` and `exclude` options are also supported (see [module rules](https://webpack.js.org/configuration/module)).
70+
71+
### `sourceMap`
72+
73+
Type: `Boolean|Object` - default: `false`
74+
75+
Enable (and configure) source map support. Use [PostCss SourceMap options](https://github.com/postcss/postcss-loader#sourcemap). Default configuration when enabled: `{ inline: false }`.
76+
77+
```js
78+
module.exports = {
79+
optimization: {
80+
minimizer: [
81+
new CssnanoPlugin({
82+
sourceMap: true
83+
})
84+
]
85+
}
86+
};
87+
```
88+
89+
### `cssnanoOptions`
90+
91+
Type: `Object` - default: `{ preset: 'default' }`
92+
93+
Cssnano optimisations [options](https://cssnano.co/guides/optimisations).
94+
95+
```js
96+
module.exports = {
97+
optimization: {
98+
minimizer: [
99+
new CssnanoPlugin({
100+
cssnanoOptions: ['default', {
101+
discardComments: { removeAll: true }
102+
}]
103+
})
104+
]
105+
}
106+
};
107+
```
108+
109+
## Examples
110+
111+
### Use sourcemaps
112+
113+
Don't forget to enable `sourceMap` options for all loaders.
114+
115+
```js
116+
const CssnanoPlugin = require('cssnano-webpack-plugin');
117+
118+
module.exports = {
119+
module: {
120+
loaders: [
121+
{
122+
test: /.s?css$/,
123+
use: [
124+
MiniCssExtractPlugin.loader,
125+
{ loader: 'css-loader', options: { sourceMap: true } },
126+
{ loader: 'sass-loader', options: { sourceMap: true } }
127+
]
128+
}
129+
]
130+
},
131+
optimization: {
132+
minimizer: [
133+
new CssnanoPlugin({
134+
sourceMap: true
135+
})
136+
]
137+
}
138+
};
139+
```
140+
141+
### Remove all comments
142+
143+
Remove all comments (including comments starting with `/*!`).
144+
145+
```js
146+
module.exports = {
147+
optimization: {
148+
minimizer: [
149+
new CssnanoPlugin({
150+
cssProcessorPluginOptions: {
151+
preset: ['default', { discardComments: { removeAll: true } }]
152+
}
153+
})
154+
]
155+
}
156+
};
157+
```
158+
159+
## License
160+
161+
[MIT](./LICENSE)

0 commit comments

Comments
 (0)