| 1 | 'use strict';
|
|---|
| 2 | /**
|
|---|
| 3 | * @author Ben Briggs
|
|---|
| 4 | * @license MIT
|
|---|
| 5 | * @module cssnano:preset:default
|
|---|
| 6 | * @overview
|
|---|
| 7 | *
|
|---|
| 8 | * This default preset for cssnano only includes transforms that make no
|
|---|
| 9 | * assumptions about your CSS other than what is passed in. In previous
|
|---|
| 10 | * iterations of cssnano, assumptions were made about your CSS which caused
|
|---|
| 11 | * output to look different in certain use cases, but not others. These
|
|---|
| 12 | * transforms have been moved from the defaults to other presets, to make
|
|---|
| 13 | * this preset require only minimal configuration.
|
|---|
| 14 | */
|
|---|
| 15 |
|
|---|
| 16 | const cssDeclarationSorter = require('css-declaration-sorter');
|
|---|
| 17 | const postcssDiscardComments = require('postcss-discard-comments');
|
|---|
| 18 | const postcssReduceInitial = require('postcss-reduce-initial');
|
|---|
| 19 | const postcssMinifyGradients = require('postcss-minify-gradients');
|
|---|
| 20 | const postcssSvgo = require('postcss-svgo');
|
|---|
| 21 | const postcssReduceTransforms = require('postcss-reduce-transforms');
|
|---|
| 22 | const postcssConvertValues = require('postcss-convert-values');
|
|---|
| 23 | const postcssCalc = require('postcss-calc');
|
|---|
| 24 | const postcssColormin = require('postcss-colormin');
|
|---|
| 25 | const postcssOrderedValues = require('postcss-ordered-values');
|
|---|
| 26 | const postcssMinifySelectors = require('postcss-minify-selectors');
|
|---|
| 27 | const postcssMinifyParams = require('postcss-minify-params');
|
|---|
| 28 | const postcssNormalizeCharset = require('postcss-normalize-charset');
|
|---|
| 29 | const postcssMinifyFontValues = require('postcss-minify-font-values');
|
|---|
| 30 | const postcssNormalizeUrl = require('postcss-normalize-url');
|
|---|
| 31 | const postcssMergeLonghand = require('postcss-merge-longhand');
|
|---|
| 32 | const postcssDiscardDuplicates = require('postcss-discard-duplicates');
|
|---|
| 33 | const postcssDiscardOverridden = require('postcss-discard-overridden');
|
|---|
| 34 | const postcssNormalizeRepeatStyle = require('postcss-normalize-repeat-style');
|
|---|
| 35 | const postcssMergeRules = require('postcss-merge-rules');
|
|---|
| 36 | const postcssDiscardEmpty = require('postcss-discard-empty');
|
|---|
| 37 | const postcssUniqueSelectors = require('postcss-unique-selectors');
|
|---|
| 38 | const postcssNormalizeString = require('postcss-normalize-string');
|
|---|
| 39 | const postcssNormalizePositions = require('postcss-normalize-positions');
|
|---|
| 40 | const postcssNormalizeWhitespace = require('postcss-normalize-whitespace');
|
|---|
| 41 | const postcssNormalizeUnicode = require('postcss-normalize-unicode');
|
|---|
| 42 | const postcssNormalizeDisplayValues = require('postcss-normalize-display-values');
|
|---|
| 43 | const postcssNormalizeTimingFunctions = require('postcss-normalize-timing-functions');
|
|---|
| 44 | const { rawCache } = require('cssnano-utils');
|
|---|
| 45 |
|
|---|
| 46 | /** @typedef {{
|
|---|
| 47 | discardComments?: false | import('postcss-discard-comments').Options & { exclude?: true},
|
|---|
| 48 | reduceInitial?: false | { exclude?: true}
|
|---|
| 49 | minifyGradients?: false | { exclude?: true}
|
|---|
| 50 | svgo?: false | import('postcss-svgo').Options & { exclude?: true},
|
|---|
| 51 | reduceTransforms?: false | { exclude?: true}
|
|---|
| 52 | convertValues?: false | import('postcss-convert-values').Options & { exclude?: true},
|
|---|
| 53 | calc?: false | import('postcss-calc').PostCssCalcOptions & { exclude?: true},
|
|---|
| 54 | colormin?: false | Record<string, any> & { exclude?: true},
|
|---|
| 55 | orderedValues?: false | { exclude?: true},
|
|---|
| 56 | minifySelectors?: false | { exclude?: true},
|
|---|
| 57 | minifyParams?: false | { exclude?: true},
|
|---|
| 58 | normalizeCharset?: false | import('postcss-normalize-charset').Options & { exclude?: true},
|
|---|
| 59 | minifyFontValues?: false | import('postcss-minify-font-values').Options & { exclude?: true},
|
|---|
| 60 | normalizeUrl?: false | import('postcss-normalize-url').Options & { exclude?: true},
|
|---|
| 61 | mergeLonghand?: false | { exclude?: true},
|
|---|
| 62 | discardDuplicates?: false | { exclude?: true},
|
|---|
| 63 | discardOverridden?: false | { exclude?: true},
|
|---|
| 64 | normalizeRepeatStyle?: false | { exclude?: true},
|
|---|
| 65 | mergeRules?: false | { exclude?: true},
|
|---|
| 66 | discardEmpty?: false | { exclude?: true},
|
|---|
| 67 | uniqueSelectors?: false | { exclude?: true},
|
|---|
| 68 | normalizeString?: false | import('postcss-normalize-string').Options & { exclude?: true},
|
|---|
| 69 | normalizePositions?: false | { exclude?: true},
|
|---|
| 70 | normalizeWhitespace?: false| { exclude?: true},
|
|---|
| 71 | normalizeUnicode?: false | { exclude?: true},
|
|---|
| 72 | normalizeDisplayValues?: false | { exclude?: true},
|
|---|
| 73 | normalizeTimingFunctions?: false | { exclude?: true},
|
|---|
| 74 | rawCache?: false | { exclude?: true}}} Options */
|
|---|
| 75 |
|
|---|
| 76 | const defaultOpts = {
|
|---|
| 77 | convertValues: {
|
|---|
| 78 | length: false,
|
|---|
| 79 | },
|
|---|
| 80 | normalizeCharset: {
|
|---|
| 81 | add: false,
|
|---|
| 82 | },
|
|---|
| 83 | cssDeclarationSorter: {
|
|---|
| 84 | keepOverrides: true,
|
|---|
| 85 | },
|
|---|
| 86 | };
|
|---|
| 87 |
|
|---|
| 88 | /**
|
|---|
| 89 | * @param {Options} opts
|
|---|
| 90 | * @return {{plugins: [import('postcss').PluginCreator<any>, boolean | Record<string, any> | undefined][]}}
|
|---|
| 91 | */
|
|---|
| 92 | function defaultPreset(opts = {}) {
|
|---|
| 93 | const options = Object.assign({}, defaultOpts, opts);
|
|---|
| 94 |
|
|---|
| 95 | /** @type {[import('postcss').PluginCreator<any>, boolean | Record<string, any> | undefined][]} **/
|
|---|
| 96 | const plugins = [
|
|---|
| 97 | [postcssDiscardComments, options.discardComments],
|
|---|
| 98 | [postcssMinifyGradients, options.minifyGradients],
|
|---|
| 99 | [postcssReduceInitial, options.reduceInitial],
|
|---|
| 100 | [postcssSvgo, options.svgo],
|
|---|
| 101 | [postcssNormalizeDisplayValues, options.normalizeDisplayValues],
|
|---|
| 102 | [postcssReduceTransforms, options.reduceTransforms],
|
|---|
| 103 | [postcssColormin, options.colormin],
|
|---|
| 104 | [postcssNormalizeTimingFunctions, options.normalizeTimingFunctions],
|
|---|
| 105 | [postcssCalc, options.calc],
|
|---|
| 106 | [postcssConvertValues, options.convertValues],
|
|---|
| 107 | [postcssOrderedValues, options.orderedValues],
|
|---|
| 108 | [postcssMinifySelectors, options.minifySelectors],
|
|---|
| 109 | [postcssMinifyParams, options.minifyParams],
|
|---|
| 110 | [postcssNormalizeCharset, options.normalizeCharset],
|
|---|
| 111 | [postcssDiscardOverridden, options.discardOverridden],
|
|---|
| 112 | [postcssNormalizeString, options.normalizeString],
|
|---|
| 113 | [postcssNormalizeUnicode, options.normalizeUnicode],
|
|---|
| 114 | [postcssMinifyFontValues, options.minifyFontValues],
|
|---|
| 115 | [postcssNormalizeUrl, options.normalizeUrl],
|
|---|
| 116 | [postcssNormalizeRepeatStyle, options.normalizeRepeatStyle],
|
|---|
| 117 | [postcssNormalizePositions, options.normalizePositions],
|
|---|
| 118 | [postcssNormalizeWhitespace, options.normalizeWhitespace],
|
|---|
| 119 | [postcssMergeLonghand, options.mergeLonghand],
|
|---|
| 120 | [postcssDiscardDuplicates, options.discardDuplicates],
|
|---|
| 121 | [postcssMergeRules, options.mergeRules],
|
|---|
| 122 | [postcssDiscardEmpty, options.discardEmpty],
|
|---|
| 123 | [postcssUniqueSelectors, options.uniqueSelectors],
|
|---|
| 124 | [cssDeclarationSorter, options.cssDeclarationSorter],
|
|---|
| 125 | [rawCache, options.rawCache],
|
|---|
| 126 | ];
|
|---|
| 127 |
|
|---|
| 128 | return { plugins };
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | module.exports = defaultPreset;
|
|---|