Skip to content

Commit f1e3993

Browse files
committed
Use local version of postcss-nano
1 parent 22f6621 commit f1e3993

File tree

3 files changed

+231
-19
lines changed

3 files changed

+231
-19
lines changed

lib/nano.js

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
var decamelize = require('decamelize');
2+
var defined = require('defined');
3+
var assign = require('object-assign');
4+
var postcss = require('postcss');
5+
6+
// Processors
7+
var postcssFilterPlugins = require('postcss-filter-plugins');
8+
var postcssDiscardComments = require('postcss-discard-comments');
9+
var postcssReduceInitial = require('postcss-reduce-initial');
10+
var postcssMinifyGradients = require('postcss-minify-gradients');
11+
var postcssSvgo = require('postcss-svgo');
12+
var postcssReduceTransforms = require('postcss-reduce-transforms');
13+
var autoprefixer = require('autoprefixer');
14+
var postcssZindex = require('postcss-zindex');
15+
var postcssConvertValues = require('postcss-convert-values');
16+
var postcssCalc = require('postcss-calc');
17+
var postcssColormin = require('postcss-colormin');
18+
var postcssOrderedValues = require('postcss-ordered-values');
19+
var postcssMinifySelectors = require('postcss-minify-selectors');
20+
var postcssMinifyParams = require('postcss-minify-params');
21+
var postcssNormalizeCharset = require('postcss-normalize-charset');
22+
var postcssMinifyFontValues = require('postcss-minify-font-values');
23+
var postcssDiscardUnused = require('postcss-discard-unused');
24+
var postcssNormalizeUrl = require('postcss-normalize-url');
25+
var postcssMergeIdents = require('postcss-merge-idents');
26+
var postcssReduceIdents = require('postcss-reduce-idents');
27+
var postcssMergeLonghand = require('postcss-merge-longhand');
28+
var postcssDiscardDuplicates = require('postcss-discard-duplicates');
29+
var postcssDiscardOverridden = require('postcss-discard-overridden');
30+
var postcssMergeRules = require('postcss-merge-rules');
31+
var postcssDiscardEmpty = require('postcss-discard-empty');
32+
var postcssUniqueSelectors = require('postcss-unique-selectors');
33+
34+
35+
var functionOptimiser = require('cssnano/dist/lib/functionOptimiser');
36+
var filterOptimiser = require('cssnano/dist/lib/filterOptimiser');
37+
var reduceBackgroundRepeat = require('cssnano/dist/lib/reduceBackgroundRepeat');
38+
var reducePositions = require('cssnano/dist/lib/reducePositions');
39+
var core = require('cssnano/dist/lib/core');
40+
var reduceTimingFunctions = require('cssnano/dist/lib/reduceTimingFunctions');
41+
var styleCache = require('cssnano/dist/lib/styleCache');
42+
43+
/**
44+
* Deprecation warnings
45+
*/
46+
47+
var warnOnce = require('cssnano/dist/lib/warnOnce');
48+
49+
var processors = {
50+
postcssFilterPlugins: function() { return postcssFilterPlugins({silent: true}) },
51+
postcssDiscardComments: postcssDiscardComments,
52+
postcssMinifyGradients: postcssMinifyGradients,
53+
postcssReduceInitial: postcssReduceInitial,
54+
postcssSvgo: postcssSvgo,
55+
postcssReduceTransforms: postcssReduceTransforms,
56+
autoprefixer: autoprefixer,
57+
postcssZindex: postcssZindex,
58+
postcssConvertValues: postcssConvertValues,
59+
reduceTimingFunctions: reduceTimingFunctions,
60+
postcssCalc: postcssCalc,
61+
postcssColormin: postcssColormin,
62+
postcssOrderedValues: postcssOrderedValues,
63+
postcssMinifySelectors: postcssMinifySelectors,
64+
postcssMinifyParams: postcssMinifyParams,
65+
postcssNormalizeCharset: postcssNormalizeCharset,
66+
postcssDiscardOverridden: postcssDiscardOverridden,
67+
// minify-font-values should be run before discard-unused
68+
postcssMinifyFontValues: postcssMinifyFontValues,
69+
postcssDiscardUnused: postcssDiscardUnused,
70+
postcssNormalizeUrl: postcssNormalizeUrl,
71+
functionOptimiser: functionOptimiser,
72+
filterOptimiser: filterOptimiser,
73+
reduceBackgroundRepeat: reduceBackgroundRepeat,
74+
reducePositions: reducePositions,
75+
core: core,
76+
// Optimisations after this are sensitive to previous optimisations in
77+
// the pipe, such as whitespace normalising/selector re-ordering
78+
postcssMergeIdents: postcssMergeIdents,
79+
postcssReduceIdents: postcssReduceIdents,
80+
postcssMergeLonghand: postcssMergeLonghand,
81+
postcssDiscardDuplicates: postcssDiscardDuplicates,
82+
postcssMergeRules: postcssMergeRules,
83+
postcssDiscardEmpty: postcssDiscardEmpty,
84+
postcssUniqueSelectors: postcssUniqueSelectors,
85+
styleCache: styleCache,
86+
};
87+
88+
var defaultOptions = {
89+
autoprefixer: {
90+
add: false,
91+
},
92+
postcssConvertValues: {
93+
length: false,
94+
},
95+
postcssNormalizeCharset: {
96+
add: false,
97+
},
98+
};
99+
100+
var safeOptions = {
101+
postcssConvertValues: {
102+
length: false,
103+
},
104+
postcssDiscardUnused: {
105+
disable: true,
106+
},
107+
postcssMergeIdents: {
108+
disable: true,
109+
},
110+
postcssReduceIdents: {
111+
counterStyle: false,
112+
keyframes: false,
113+
},
114+
postcssNormalizeUrl: {
115+
stripWWW: false,
116+
},
117+
postcssZindex: {
118+
disable: true,
119+
},
120+
};
121+
122+
var nanoPluginHandler = function nanoPluginHandler (options) {
123+
if (typeof options === 'undefined') options = {}
124+
125+
// Prevent PostCSS from throwing when safe is defined
126+
if (options.safe === true) {
127+
options.isSafe = true;
128+
options.safe = null;
129+
}
130+
131+
var safe = options.isSafe;
132+
var proc = postcss();
133+
134+
if (typeof options.fontFamily !== 'undefined' || typeof options.minifyFontWeight !== 'undefined') {
135+
warnOnce('The fontFamily & minifyFontWeight options have been ' +
136+
'consolidated into minifyFontValues, and are now deprecated.');
137+
if (!options.minifyFontValues) {
138+
options.minifyFontValues = options.fontFamily;
139+
}
140+
}
141+
142+
if (typeof options.singleCharset !== 'undefined') {
143+
warnOnce('The singleCharset option has been renamed to ' +
144+
'normalizeCharset, and is now deprecated.');
145+
options.normalizeCharset = options.singleCharset;
146+
}
147+
148+
Object.keys(processors).forEach(function(plugin) {
149+
var shortName = plugin.replace('postcss', '');
150+
shortName = shortName.slice(0, 1).toLowerCase() + shortName.slice(1);
151+
152+
var opts = defined(
153+
options[shortName],
154+
options[plugin],
155+
options[decamelize(plugin, '-')]
156+
);
157+
158+
if (opts === false) {
159+
opts = {disable: true};
160+
}
161+
162+
opts = assign({},
163+
defaultOptions[plugin],
164+
safe ? safeOptions[plugin] : null,
165+
opts
166+
);
167+
168+
if (!opts.disable) {
169+
proc.use(processors[plugin](opts));
170+
}
171+
172+
});
173+
174+
return proc;
175+
}
176+
177+
var cssnano = postcss.plugin('cssnano', nanoPluginHandler)
178+
179+
180+
cssnano.process = function (css, options) {
181+
if (typeof options === 'undefined') options = {}
182+
options.map = options.map || (options.sourcemap ? true : null);
183+
return postcss([cssnano(options)]).process(css, options);
184+
};
185+
186+
module.exports = cssnano;

lib/processCss.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var localByDefault = require("postcss-modules-local-by-default");
1313
var extractImports = require("postcss-modules-extract-imports");
1414
var modulesScope = require("postcss-modules-scope");
1515
var modulesValues = require("postcss-modules-values");
16-
var cssnano = require("cssnano");
16+
var cssnano = require("./nano");
1717

1818
var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
1919
return function(css) {

package.json

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,55 @@
33
"version": "0.25.0",
44
"author": "Tobias Koppers @sokra",
55
"description": "css loader module for webpack",
6-
"engines": {
7-
"node": ">=0.12.0"
8-
},
96
"dependencies": {
10-
"babel-code-frame": "^6.11.0",
11-
"css-selector-tokenizer": "^0.6.0",
7+
"autoprefixer": "6.4.1",
8+
"babel-code-frame": "6.11.0",
9+
"css-selector-tokenizer": "0.6.0",
1210
"cssnano": ">=2.6.1 <4",
11+
"decamelize": "1.2.0",
12+
"defined": "1.0.0",
1313
"loader-utils": "~0.2.2",
14-
"lodash.camelcase": "^3.0.1",
15-
"object-assign": "^4.0.1",
16-
"postcss": "^5.0.6",
17-
"postcss-modules-extract-imports": "^1.0.0",
18-
"postcss-modules-local-by-default": "^1.0.1",
19-
"postcss-modules-scope": "^1.0.0",
20-
"postcss-modules-values": "^1.1.0",
21-
"source-list-map": "^0.1.4"
14+
"lodash.camelcase": "3.0.1",
15+
"object-assign": "4.1.0",
16+
"postcss": "5.2.0",
17+
"postcss-calc": "5.3.1",
18+
"postcss-colormin": "2.2.1",
19+
"postcss-convert-values": "2.4.0",
20+
"postcss-discard-comments": "2.0.4",
21+
"postcss-discard-duplicates": "2.0.1",
22+
"postcss-discard-empty": "2.1.0",
23+
"postcss-discard-overridden": "0.1.1",
24+
"postcss-discard-unused": "2.2.1",
25+
"postcss-filter-plugins": "2.0.1",
26+
"postcss-merge-idents": "2.1.7",
27+
"postcss-merge-longhand": "2.0.1",
28+
"postcss-merge-rules": "2.0.10",
29+
"postcss-minify-font-values": "1.0.5",
30+
"postcss-minify-gradients": "1.0.3",
31+
"postcss-minify-params": "1.0.5",
32+
"postcss-minify-selectors": "2.0.5",
33+
"postcss-modules-extract-imports": "1.0.0",
34+
"postcss-modules-local-by-default": "1.0.1",
35+
"postcss-modules-scope": "1.0.0",
36+
"postcss-modules-values": "1.1.0",
37+
"postcss-normalize-charset": "1.1.0",
38+
"postcss-normalize-url": "3.0.7",
39+
"postcss-ordered-values": "2.2.2",
40+
"postcss-reduce-idents": "2.3.0",
41+
"postcss-reduce-initial": "1.0.0",
42+
"postcss-reduce-transforms": "1.0.3",
43+
"postcss-svgo": "2.1.4",
44+
"postcss-unique-selectors": "2.0.2",
45+
"postcss-zindex": "2.1.1",
46+
"source-list-map": "0.1.4"
2247
},
2348
"devDependencies": {
24-
"codecov.io": "^0.1.2",
25-
"coveralls": "^2.11.2",
26-
"istanbul": "^0.3.13",
27-
"mocha": "^2.2.4",
28-
"should": "^7.0.1"
49+
"bluebird": "3.4.6",
50+
"codecov.io": "0.1.2",
51+
"coveralls": "2.11.2",
52+
"istanbul": "0.3.13",
53+
"mocha": "2.2.4",
54+
"should": "7.0.1"
2955
},
3056
"scripts": {
3157
"test": "mocha",

0 commit comments

Comments
 (0)