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