cssnano 5.0.16 → 5.0.17
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 +7 -14
- package/{dist → src}/index.js +49 -53
- package/quickstart.js +0 -48
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cssnano",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.17",
|
|
4
4
|
"description": "A modular minifier, built on top of the PostCSS ecosystem.",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "src/index.js",
|
|
6
6
|
"funding": {
|
|
7
7
|
"type": "opencollective",
|
|
8
8
|
"url": "https://opencollective.com/cssnano"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"cssnano-preset-default": "^5.1.
|
|
21
|
+
"cssnano-preset-default": "^5.1.12",
|
|
22
22
|
"lilconfig": "^2.0.3",
|
|
23
23
|
"yaml": "^1.10.2"
|
|
24
24
|
},
|
|
@@ -30,11 +30,9 @@
|
|
|
30
30
|
},
|
|
31
31
|
"repository": "cssnano/cssnano",
|
|
32
32
|
"files": [
|
|
33
|
-
"
|
|
34
|
-
"LICENSE-MIT"
|
|
35
|
-
"quickstart.js"
|
|
33
|
+
"src",
|
|
34
|
+
"LICENSE-MIT"
|
|
36
35
|
],
|
|
37
|
-
"tonicExampleFilename": "quickstart.js",
|
|
38
36
|
"bugs": {
|
|
39
37
|
"url": "https://github.com/cssnano/cssnano/issues"
|
|
40
38
|
},
|
|
@@ -43,17 +41,12 @@
|
|
|
43
41
|
},
|
|
44
42
|
"devDependencies": {
|
|
45
43
|
"autoprefixer": "^10.3.7",
|
|
46
|
-
"cssnano-preset-advanced": "^5.1.
|
|
47
|
-
"cssnano-preset-lite": "^2.0.
|
|
44
|
+
"cssnano-preset-advanced": "^5.1.12",
|
|
45
|
+
"cssnano-preset-lite": "^2.0.3",
|
|
48
46
|
"postcss": "^8.2.15"
|
|
49
47
|
},
|
|
50
48
|
"peerDependencies": {
|
|
51
49
|
"postcss": "^8.2.15"
|
|
52
50
|
},
|
|
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
51
|
"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
52
|
}
|
package/{dist → src}/index.js
RENAMED
|
@@ -1,35 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
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
|
+
const postcss = require('postcss');
|
|
4
|
+
const yaml = require('yaml');
|
|
5
|
+
const { lilconfigSync } = require('lilconfig');
|
|
17
6
|
|
|
18
7
|
const cssnano = 'cssnano';
|
|
8
|
+
|
|
19
9
|
/*
|
|
20
10
|
* @param {string} moduleId
|
|
21
11
|
* @returns {boolean}
|
|
22
12
|
*/
|
|
23
|
-
|
|
24
13
|
function isResolvable(moduleId) {
|
|
25
14
|
try {
|
|
26
15
|
require.resolve(moduleId);
|
|
27
|
-
|
|
28
16
|
return true;
|
|
29
17
|
} catch (e) {
|
|
30
18
|
return false;
|
|
31
19
|
}
|
|
32
20
|
}
|
|
21
|
+
|
|
33
22
|
/*
|
|
34
23
|
* preset can be one of four possibilities:
|
|
35
24
|
* preset = 'default'
|
|
@@ -38,7 +27,6 @@ function isResolvable(moduleId) {
|
|
|
38
27
|
* preset = {plugins: []} <- already invoked function
|
|
39
28
|
*/
|
|
40
29
|
|
|
41
|
-
|
|
42
30
|
function resolvePreset(preset) {
|
|
43
31
|
let fn, options;
|
|
44
32
|
|
|
@@ -48,44 +36,47 @@ function resolvePreset(preset) {
|
|
|
48
36
|
} else {
|
|
49
37
|
fn = preset;
|
|
50
38
|
options = {};
|
|
51
|
-
}
|
|
52
|
-
|
|
39
|
+
}
|
|
53
40
|
|
|
41
|
+
// For JS setups where we invoked the preset already
|
|
54
42
|
if (preset.plugins) {
|
|
55
43
|
return preset.plugins;
|
|
56
|
-
}
|
|
57
|
-
|
|
44
|
+
}
|
|
58
45
|
|
|
46
|
+
// Provide an alias for the default preset, as it is built-in.
|
|
59
47
|
if (fn === 'default') {
|
|
60
48
|
return require('cssnano-preset-default')(options).plugins;
|
|
61
|
-
}
|
|
62
|
-
|
|
49
|
+
}
|
|
63
50
|
|
|
51
|
+
// For non-JS setups; we'll need to invoke the preset ourselves.
|
|
64
52
|
if (typeof fn === 'function') {
|
|
65
53
|
return fn(options).plugins;
|
|
66
|
-
}
|
|
67
|
-
|
|
54
|
+
}
|
|
68
55
|
|
|
56
|
+
// Try loading a preset from node_modules
|
|
69
57
|
if (isResolvable(fn)) {
|
|
70
58
|
return require(fn)(options).plugins;
|
|
71
59
|
}
|
|
72
60
|
|
|
73
|
-
const sugar = `cssnano-preset-${fn}`;
|
|
61
|
+
const sugar = `cssnano-preset-${fn}`;
|
|
74
62
|
|
|
63
|
+
// Try loading a preset from node_modules (sugar)
|
|
75
64
|
if (isResolvable(sugar)) {
|
|
76
65
|
return require(sugar)(options).plugins;
|
|
77
|
-
}
|
|
78
|
-
|
|
66
|
+
}
|
|
79
67
|
|
|
80
|
-
|
|
68
|
+
// If all else fails, we probably have a typo in the config somewhere
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Cannot load preset "${fn}". Please check your configuration for errors and try again.`
|
|
71
|
+
);
|
|
81
72
|
}
|
|
73
|
+
|
|
82
74
|
/*
|
|
83
75
|
* cssnano will look for configuration firstly as options passed
|
|
84
76
|
* directly to it, and failing this it will use lilconfig to
|
|
85
77
|
* load an external file.
|
|
86
78
|
*/
|
|
87
79
|
|
|
88
|
-
|
|
89
80
|
function resolveConfig(options) {
|
|
90
81
|
if (options.preset) {
|
|
91
82
|
return resolvePreset(options.preset);
|
|
@@ -96,17 +87,27 @@ function resolveConfig(options) {
|
|
|
96
87
|
|
|
97
88
|
if (options.configFile) {
|
|
98
89
|
searchPath = null;
|
|
99
|
-
configPath =
|
|
90
|
+
configPath = path.resolve(process.cwd(), options.configFile);
|
|
100
91
|
}
|
|
101
92
|
|
|
102
|
-
const configExplorer =
|
|
103
|
-
searchPlaces: [
|
|
93
|
+
const configExplorer = lilconfigSync(cssnano, {
|
|
94
|
+
searchPlaces: [
|
|
95
|
+
'package.json',
|
|
96
|
+
'.cssnanorc',
|
|
97
|
+
'.cssnanorc.json',
|
|
98
|
+
'.cssnanorc.yaml',
|
|
99
|
+
'.cssnanorc.yml',
|
|
100
|
+
'.cssnanorc.js',
|
|
101
|
+
'cssnano.config.js',
|
|
102
|
+
],
|
|
104
103
|
loaders: {
|
|
105
|
-
'.yaml': (filepath, content) =>
|
|
106
|
-
'.yml': (filepath, content) =>
|
|
107
|
-
}
|
|
104
|
+
'.yaml': (filepath, content) => yaml.parse(content),
|
|
105
|
+
'.yml': (filepath, content) => yaml.parse(content),
|
|
106
|
+
},
|
|
108
107
|
});
|
|
109
|
-
const config = configPath
|
|
108
|
+
const config = configPath
|
|
109
|
+
? configExplorer.load(configPath)
|
|
110
|
+
: configExplorer.search(searchPath);
|
|
110
111
|
|
|
111
112
|
if (config === null) {
|
|
112
113
|
return resolvePreset('default');
|
|
@@ -118,15 +119,12 @@ function resolveConfig(options) {
|
|
|
118
119
|
const cssnanoPlugin = (options = {}) => {
|
|
119
120
|
if (Array.isArray(options.plugins)) {
|
|
120
121
|
if (!options.preset || !options.preset.plugins) {
|
|
121
|
-
options.preset = {
|
|
122
|
-
plugins: []
|
|
123
|
-
};
|
|
122
|
+
options.preset = { plugins: [] };
|
|
124
123
|
}
|
|
125
124
|
|
|
126
|
-
options.plugins.forEach(plugin => {
|
|
125
|
+
options.plugins.forEach((plugin) => {
|
|
127
126
|
if (Array.isArray(plugin)) {
|
|
128
127
|
const [pluginDef, opts = {}] = plugin;
|
|
129
|
-
|
|
130
128
|
if (typeof pluginDef === 'string' && isResolvable(pluginDef)) {
|
|
131
129
|
options.preset.plugins.push([require(pluginDef), opts]);
|
|
132
130
|
} else {
|
|
@@ -139,26 +137,24 @@ const cssnanoPlugin = (options = {}) => {
|
|
|
139
137
|
}
|
|
140
138
|
});
|
|
141
139
|
}
|
|
142
|
-
|
|
143
140
|
const plugins = [];
|
|
144
141
|
const nanoPlugins = resolveConfig(options);
|
|
145
|
-
|
|
146
142
|
for (const nanoPlugin of nanoPlugins) {
|
|
147
143
|
if (Array.isArray(nanoPlugin)) {
|
|
148
144
|
const [processor, opts] = nanoPlugin;
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
if (
|
|
146
|
+
typeof opts === 'undefined' ||
|
|
147
|
+
(typeof opts === 'object' && !opts.exclude) ||
|
|
148
|
+
(typeof opts === 'boolean' && opts === true)
|
|
149
|
+
) {
|
|
151
150
|
plugins.push(processor(opts));
|
|
152
151
|
}
|
|
153
152
|
} else {
|
|
154
153
|
plugins.push(nanoPlugin);
|
|
155
154
|
}
|
|
156
155
|
}
|
|
157
|
-
|
|
158
|
-
return (0, _postcss.default)(plugins);
|
|
156
|
+
return postcss(plugins);
|
|
159
157
|
};
|
|
160
158
|
|
|
161
159
|
cssnanoPlugin.postcss = true;
|
|
162
|
-
|
|
163
|
-
exports.default = _default;
|
|
164
|
-
module.exports = exports.default;
|
|
160
|
+
module.exports = cssnanoPlugin;
|
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
|
-
});
|