UNPKG

makestatic-preset-optimize

Version:

Optimize lifecycle preset

86 lines (78 loc) 2.41 kB
/** * Configures standard plugins for the optimize lifecycle phase. * * Plugins are configured with sensible default values but you can override * the configuration when necessary. * * @function preset * @param {Object} options plugin options. * * @option {Object} [test] map of file test patterns. * @option {Object} [html] options for the `optimize-html` plugin. * @option {Object} [css] options for the `optimize-css` plugin. * @option {Object} [js] options for the `optimize-js` plugin. * @option {Object} [image] options for the `optimize-image` plugin. * @option {Object} [inline] options for inline script and style compression. * @option {Object} [exclude] map of excludes. * * @see /docs/api/optimize-html/ Optimize HTML * @see /docs/api/optimize-css/ Optimize CSS * @see /docs/api/optimize-js/ Optimize JS * @see /docs/api/optimize-image/ Optimize Image */ module.exports = function preset (options = {}) { let test = options.test || {} const exclude = options.exclude || {} // configuration for inline css and javascript optimization options.inline = options.inline || {} options.css = options.css || {} options.js = options.js || {} options.image = options.image || {} options.html = options.html || { removeComments: true, collapseInlineTagWhitespace: true, collapseWhitespace: true, conservativeCollapse: true, minifyCSS: options.inline.css || true, minifyJS: options.inline.js || true } // configuration for optimize lifecycle const optimizers = [ { test: test.html, plugin: require('makestatic-optimize-html'), exclude: exclude.html, options: options.html }, { test: test.css, plugin: require('makestatic-optimize-css'), exclude: exclude.css, options: options.css }, { test: test.js, plugin: require('makestatic-optimize-js'), exclude: exclude.js, options: options.js }, { test: test.image, plugin: require('makestatic-optimize-image'), exclude: exclude.image, options: options.image } ] if (options.webp) { if (options.webp instanceof RegExp) { test.webp = options.webp } optimizers.push({ test: test.webp, plugin: require('makestatic-optimize-webp'), exclude: exclude.webp, options: options.webp }) } return optimizers; }