wingsuit-designsystem / wingsuit

Twig for Storybook
GNU General Public License v2.0
91 stars 16 forks source link

Feature/compression preset #167

Closed iuscare closed 3 years ago

iuscare commented 3 years ago

This preset adds compression for css, js and html files. Following props are exposed to be used in the wingsuit.config.yml

Prop Type Desc
gzipEnabled {boolean | default: true} use gzip compression algorithm/function
brotliEnabled {boolean | default: true} use brotli compression algorithm/function
fileName {string | default: '[path][base]'} target asset filename see for more information

Example configuration:

const namespaces = require('./source/default/namespaces');

module.exports = {
  presets: [
    '@wingsuit-designsystem/preset-tailwind2',
    '@wingsuit-designsystem/preset-postcss8',
    '@wingsuit-designsystem/preset-compression',
  ],
  parameters: {
    compression: {
      gzipEnabled: true,
      brotliEnabled: false,
    },
  },
  designSystems: {
    default: {
      namespaces,
    },
  },
};

The optimized files are only generated when running the build process of drupal.

christianwiedemann commented 3 years ago

Does this preset minify and compress, or both. For example, Drupal needs only minified files and the Apache does the compression.

iuscare commented 3 years ago

Hey @christianwiedemann, when running yarn build:drupal the files are already minified without the preset. This preset only adds a layer on top of that and creates compressed files out of them. While it is true, that modern web servers have the possibility to compress the files on demand, I thought that compressing static files on each demand could be somewhat like an anti-pattern. It may be worth to outsource this work to the build process. This also gives better valuation about the real file size used in production and is portable. That was the motivation behind the preset. If we want to stick with pure webserver compression and minification during the build process is enough, we won't need the preset :wink:

christianwiedemann commented 3 years ago

Yes perfekct, we need both compressed and minified