cssnano 5.0.16 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -13
- package/{dist → src}/index.js +69 -62
- package/types/index.d.ts +16 -0
- package/quickstart.js +0 -48
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cssnano",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "A modular minifier, built on top of the PostCSS ecosystem.",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
6
7
|
"funding": {
|
|
7
8
|
"type": "opencollective",
|
|
8
9
|
"url": "https://opencollective.com/cssnano"
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
],
|
|
19
20
|
"license": "MIT",
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"cssnano-preset-default": "^5.1
|
|
22
|
+
"cssnano-preset-default": "^5.2.1",
|
|
22
23
|
"lilconfig": "^2.0.3",
|
|
23
24
|
"yaml": "^1.10.2"
|
|
24
25
|
},
|
|
@@ -30,11 +31,10 @@
|
|
|
30
31
|
},
|
|
31
32
|
"repository": "cssnano/cssnano",
|
|
32
33
|
"files": [
|
|
33
|
-
"
|
|
34
|
+
"src",
|
|
34
35
|
"LICENSE-MIT",
|
|
35
|
-
"
|
|
36
|
+
"types"
|
|
36
37
|
],
|
|
37
|
-
"tonicExampleFilename": "quickstart.js",
|
|
38
38
|
"bugs": {
|
|
39
39
|
"url": "https://github.com/cssnano/cssnano/issues"
|
|
40
40
|
},
|
|
@@ -43,17 +43,12 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"autoprefixer": "^10.3.7",
|
|
46
|
-
"cssnano-preset-advanced": "^5.
|
|
47
|
-
"cssnano-preset-lite": "^2.0
|
|
46
|
+
"cssnano-preset-advanced": "^5.2.2",
|
|
47
|
+
"cssnano-preset-lite": "^2.1.0",
|
|
48
48
|
"postcss": "^8.2.15"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"postcss": "^8.2.15"
|
|
52
52
|
},
|
|
53
|
-
"scripts": {
|
|
54
|
-
"bundle-size": "webpack --json --config src/__tests__/_webpack.config.js | webpack-bundle-size-analyzer",
|
|
55
|
-
"prebuild": "rimraf dist",
|
|
56
|
-
"build": "babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\""
|
|
57
|
-
},
|
|
58
53
|
"readme": "# cssnano\n\nFor documentation, please see the following links:\n\n* Repository: https://github.com/cssnano/cssnano\n* Website: http://cssnano.co\n"
|
|
59
54
|
}
|
package/{dist → src}/index.js
RENAMED
|
@@ -1,44 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
var _postcss = _interopRequireDefault(require("postcss"));
|
|
11
|
-
|
|
12
|
-
var _yaml = _interopRequireDefault(require("yaml"));
|
|
13
|
-
|
|
14
|
-
var _lilconfig = require("lilconfig");
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
'use strict';
|
|
2
|
+
const path = require('path');
|
|
3
|
+
/** @type {any} */
|
|
4
|
+
const postcss = require('postcss');
|
|
5
|
+
const yaml = require('yaml');
|
|
6
|
+
const { lilconfigSync } = require('lilconfig');
|
|
17
7
|
|
|
18
8
|
const cssnano = 'cssnano';
|
|
19
|
-
|
|
9
|
+
|
|
10
|
+
/** @typedef {{preset?: any, plugins?: any[], configFile?: string}} Options */
|
|
11
|
+
/**
|
|
20
12
|
* @param {string} moduleId
|
|
21
13
|
* @returns {boolean}
|
|
22
14
|
*/
|
|
23
|
-
|
|
24
15
|
function isResolvable(moduleId) {
|
|
25
16
|
try {
|
|
26
17
|
require.resolve(moduleId);
|
|
27
|
-
|
|
28
18
|
return true;
|
|
29
19
|
} catch (e) {
|
|
30
20
|
return false;
|
|
31
21
|
}
|
|
32
22
|
}
|
|
33
|
-
|
|
23
|
+
|
|
24
|
+
/**
|
|
34
25
|
* preset can be one of four possibilities:
|
|
35
26
|
* preset = 'default'
|
|
36
27
|
* preset = ['default', {}]
|
|
37
28
|
* preset = function <- to be invoked
|
|
38
29
|
* preset = {plugins: []} <- already invoked function
|
|
30
|
+
*
|
|
31
|
+
* @param {any} preset
|
|
32
|
+
* @return {[import('postcss').PluginCreator<any>, boolean | Record<string, any> | undefined][]}}
|
|
39
33
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
34
|
function resolvePreset(preset) {
|
|
43
35
|
let fn, options;
|
|
44
36
|
|
|
@@ -48,65 +40,80 @@ function resolvePreset(preset) {
|
|
|
48
40
|
} else {
|
|
49
41
|
fn = preset;
|
|
50
42
|
options = {};
|
|
51
|
-
}
|
|
52
|
-
|
|
43
|
+
}
|
|
53
44
|
|
|
45
|
+
// For JS setups where we invoked the preset already
|
|
54
46
|
if (preset.plugins) {
|
|
55
47
|
return preset.plugins;
|
|
56
|
-
}
|
|
57
|
-
|
|
48
|
+
}
|
|
58
49
|
|
|
50
|
+
// Provide an alias for the default preset, as it is built-in.
|
|
59
51
|
if (fn === 'default') {
|
|
60
52
|
return require('cssnano-preset-default')(options).plugins;
|
|
61
|
-
}
|
|
62
|
-
|
|
53
|
+
}
|
|
63
54
|
|
|
55
|
+
// For non-JS setups; we'll need to invoke the preset ourselves.
|
|
64
56
|
if (typeof fn === 'function') {
|
|
65
57
|
return fn(options).plugins;
|
|
66
|
-
}
|
|
67
|
-
|
|
58
|
+
}
|
|
68
59
|
|
|
60
|
+
// Try loading a preset from node_modules
|
|
69
61
|
if (isResolvable(fn)) {
|
|
70
62
|
return require(fn)(options).plugins;
|
|
71
63
|
}
|
|
72
64
|
|
|
73
|
-
const sugar = `cssnano-preset-${fn}`;
|
|
65
|
+
const sugar = `cssnano-preset-${fn}`;
|
|
74
66
|
|
|
67
|
+
// Try loading a preset from node_modules (sugar)
|
|
75
68
|
if (isResolvable(sugar)) {
|
|
76
69
|
return require(sugar)(options).plugins;
|
|
77
|
-
}
|
|
78
|
-
|
|
70
|
+
}
|
|
79
71
|
|
|
80
|
-
|
|
72
|
+
// If all else fails, we probably have a typo in the config somewhere
|
|
73
|
+
throw new Error(
|
|
74
|
+
`Cannot load preset "${fn}". Please check your configuration for errors and try again.`
|
|
75
|
+
);
|
|
81
76
|
}
|
|
82
|
-
|
|
77
|
+
|
|
78
|
+
/**
|
|
83
79
|
* cssnano will look for configuration firstly as options passed
|
|
84
80
|
* directly to it, and failing this it will use lilconfig to
|
|
85
81
|
* load an external file.
|
|
86
|
-
*/
|
|
87
|
-
|
|
88
82
|
|
|
83
|
+
* @param {Options} options
|
|
84
|
+
*/
|
|
89
85
|
function resolveConfig(options) {
|
|
90
86
|
if (options.preset) {
|
|
91
87
|
return resolvePreset(options.preset);
|
|
92
88
|
}
|
|
93
89
|
|
|
90
|
+
/** @type {string | undefined} */
|
|
94
91
|
let searchPath = process.cwd();
|
|
95
|
-
let configPath =
|
|
92
|
+
let configPath = undefined;
|
|
96
93
|
|
|
97
94
|
if (options.configFile) {
|
|
98
|
-
searchPath =
|
|
99
|
-
configPath =
|
|
95
|
+
searchPath = undefined;
|
|
96
|
+
configPath = path.resolve(process.cwd(), options.configFile);
|
|
100
97
|
}
|
|
101
98
|
|
|
102
|
-
const configExplorer =
|
|
103
|
-
searchPlaces: [
|
|
99
|
+
const configExplorer = lilconfigSync(cssnano, {
|
|
100
|
+
searchPlaces: [
|
|
101
|
+
'package.json',
|
|
102
|
+
'.cssnanorc',
|
|
103
|
+
'.cssnanorc.json',
|
|
104
|
+
'.cssnanorc.yaml',
|
|
105
|
+
'.cssnanorc.yml',
|
|
106
|
+
'.cssnanorc.js',
|
|
107
|
+
'cssnano.config.js',
|
|
108
|
+
],
|
|
104
109
|
loaders: {
|
|
105
|
-
'.yaml': (filepath, content) =>
|
|
106
|
-
'.yml': (filepath, content) =>
|
|
107
|
-
}
|
|
110
|
+
'.yaml': (filepath, content) => yaml.parse(content),
|
|
111
|
+
'.yml': (filepath, content) => yaml.parse(content),
|
|
112
|
+
},
|
|
108
113
|
});
|
|
109
|
-
const config = configPath
|
|
114
|
+
const config = configPath
|
|
115
|
+
? configExplorer.load(configPath)
|
|
116
|
+
: configExplorer.search(searchPath);
|
|
110
117
|
|
|
111
118
|
if (config === null) {
|
|
112
119
|
return resolvePreset('default');
|
|
@@ -115,18 +122,20 @@ function resolveConfig(options) {
|
|
|
115
122
|
return resolvePreset(config.config.preset || config.config);
|
|
116
123
|
}
|
|
117
124
|
|
|
118
|
-
|
|
125
|
+
/**
|
|
126
|
+
* @type {import('postcss').PluginCreator<Options>}
|
|
127
|
+
* @param {Options=} options
|
|
128
|
+
* @return {import('postcss').Plugin}
|
|
129
|
+
*/
|
|
130
|
+
function cssnanoPlugin(options = {}) {
|
|
119
131
|
if (Array.isArray(options.plugins)) {
|
|
120
132
|
if (!options.preset || !options.preset.plugins) {
|
|
121
|
-
options.preset = {
|
|
122
|
-
plugins: []
|
|
123
|
-
};
|
|
133
|
+
options.preset = { plugins: [] };
|
|
124
134
|
}
|
|
125
135
|
|
|
126
|
-
options.plugins.forEach(plugin => {
|
|
136
|
+
options.plugins.forEach((plugin) => {
|
|
127
137
|
if (Array.isArray(plugin)) {
|
|
128
138
|
const [pluginDef, opts = {}] = plugin;
|
|
129
|
-
|
|
130
139
|
if (typeof pluginDef === 'string' && isResolvable(pluginDef)) {
|
|
131
140
|
options.preset.plugins.push([require(pluginDef), opts]);
|
|
132
141
|
} else {
|
|
@@ -139,26 +148,24 @@ const cssnanoPlugin = (options = {}) => {
|
|
|
139
148
|
}
|
|
140
149
|
});
|
|
141
150
|
}
|
|
142
|
-
|
|
143
151
|
const plugins = [];
|
|
144
152
|
const nanoPlugins = resolveConfig(options);
|
|
145
|
-
|
|
146
153
|
for (const nanoPlugin of nanoPlugins) {
|
|
147
154
|
if (Array.isArray(nanoPlugin)) {
|
|
148
155
|
const [processor, opts] = nanoPlugin;
|
|
149
|
-
|
|
150
|
-
|
|
156
|
+
if (
|
|
157
|
+
typeof opts === 'undefined' ||
|
|
158
|
+
(typeof opts === 'object' && !opts.exclude) ||
|
|
159
|
+
(typeof opts === 'boolean' && opts === true)
|
|
160
|
+
) {
|
|
151
161
|
plugins.push(processor(opts));
|
|
152
162
|
}
|
|
153
163
|
} else {
|
|
154
164
|
plugins.push(nanoPlugin);
|
|
155
165
|
}
|
|
156
166
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
};
|
|
167
|
+
return postcss(plugins);
|
|
168
|
+
}
|
|
160
169
|
|
|
161
170
|
cssnanoPlugin.postcss = true;
|
|
162
|
-
|
|
163
|
-
exports.default = _default;
|
|
164
|
-
module.exports = exports.default;
|
|
171
|
+
module.exports = cssnanoPlugin;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export = cssnanoPlugin;
|
|
2
|
+
/**
|
|
3
|
+
* @type {import('postcss').PluginCreator<Options>}
|
|
4
|
+
* @param {Options=} options
|
|
5
|
+
* @return {import('postcss').Plugin}
|
|
6
|
+
*/
|
|
7
|
+
declare function cssnanoPlugin(options?: Options | undefined): import('postcss').Plugin;
|
|
8
|
+
declare namespace cssnanoPlugin {
|
|
9
|
+
export { postcss, Options };
|
|
10
|
+
}
|
|
11
|
+
type Options = {
|
|
12
|
+
preset?: any;
|
|
13
|
+
plugins?: any[];
|
|
14
|
+
configFile?: string;
|
|
15
|
+
};
|
|
16
|
+
declare var postcss: true;
|
package/quickstart.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* This example targets Node 4 and up.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const cssnano = require('cssnano');
|
|
6
|
-
|
|
7
|
-
/*
|
|
8
|
-
* Add your CSS code here.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const css = `
|
|
12
|
-
h1 {
|
|
13
|
-
color: #ff0000;
|
|
14
|
-
font-weight: bold;
|
|
15
|
-
}
|
|
16
|
-
`;
|
|
17
|
-
|
|
18
|
-
/*
|
|
19
|
-
* Add any PostCSS options here. For example to enable sourcemaps, see:
|
|
20
|
-
* https://github.com/postcss/postcss/blob/master/site/source-maps.md
|
|
21
|
-
*
|
|
22
|
-
* Or for an inline sourcemap, uncomment the options below.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
const postcssOpts = {
|
|
26
|
-
// from: 'app.css',
|
|
27
|
-
// to: 'app.min.css',
|
|
28
|
-
// map: {inline: true},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/*
|
|
32
|
-
* Add your choice of preset. Note that for any value other
|
|
33
|
-
* than 'default', you will need to install the appropriate
|
|
34
|
-
* preset separately.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
const cssnanoOpts = {
|
|
38
|
-
preset: 'default',
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/*
|
|
42
|
-
* Compress the CSS asynchronously and log it to the console.
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
cssnano.process(css, postcssOpts, cssnanoOpts).then((result) => {
|
|
46
|
-
// eslint-disable-next-line no-console
|
|
47
|
-
console.log(result.css);
|
|
48
|
-
});
|