import postcssDiscardComments from '#postcss-discard-comments'; import postcssNormalizeWhitespace from '#postcss-normalize-whitespace'; import postcssDiscardEmpty from '#postcss-discard-empty'; import cssnanoUtils from '#utils'; const { rawCache } = cssnanoUtils; /** * @template {object | void} [OptionsExtends=void] * @typedef {false | OptionsExtends & {exclude?: true}} SimpleOptions */ /** * @typedef {object} LiteOptions * @property {SimpleOptions} [discardComments] * @property {SimpleOptions} [normalizeWhitespace] * @property {SimpleOptions} [discardEmpty] * @property {SimpleOptions} [rawCache] */ /** * @param {[import('postcss').PluginCreator, keyof LiteOptions][]} plugins * @param {Parameters[0]} opts * @returns {ReturnType["plugins"]} */ function configurePlugins(plugins, opts = {}) { const defaults = /** @type {LiteOptions} */ ({}); // Merge option properties for each plugin return plugins.map(([plugin, opt]) => { const defaultProps = defaults[opt] ?? {}; const presetProps = opts[opt] ?? {}; return [ plugin, presetProps !== false ? { ...defaultProps, ...presetProps } : { exclude: true }, ]; }); } /** * Safe and minimum transformation with just removing whitespaces, line breaks and comments * * @param {LiteOptions} opts * @returns {{ plugins: [import('postcss').PluginCreator, LiteOptions[keyof LiteOptions]][] }} */ function litePreset(opts = {}) { return { plugins: configurePlugins( [ [postcssDiscardComments, 'discardComments'], [postcssNormalizeWhitespace, 'normalizeWhitespace'], [postcssDiscardEmpty, 'discardEmpty'], [rawCache, 'rawCache'], ], opts ), }; } const moduleExports = litePreset; export { moduleExports as default, moduleExports as 'module.exports' };