embroider-build / addon-blueprint

Blueprint for v2-formatted Ember addons
MIT License
28 stars 23 forks source link

We can minify template output with a config change to babel #249

Closed NullVoxPopuli closed 3 months ago

NullVoxPopuli commented 5 months ago

Found this works pretty well: https://github.com/mainmatter/ember-hbs-minifier

renaming babel.config.json to babel.config.cjs:

'use strict';

const minifier = require('ember-hbs-minifier/hbs-minifier-plugin').createRegistryPlugin;

module.exports = {
  plugins: [
    '@embroider/addon-dev/template-colocation-plugin',
    [
      'babel-plugin-ember-template-compilation',
      {
        targetFormat: 'hbs',
        transforms: [minifier({})],
      },
    ],
    ['module:decorator-transforms', { runtime: { import: 'decorator-transforms/runtime' } }],
  ],
};

Docs on transforms: https://github.com/emberjs/babel-plugin-ember-template-compilation/?tab=readme-ov-file#common-options


I kinda want to propose this behavior be default, but I don't yet know if there are any drawbacks.

The README for ember-hbs-minifier says:

Disclaimer: This is an experiment and might change in the future. Do not use this for production yet unless you understand the consequences!

which like... :shrug: it's just an AST transform.

NullVoxPopuli commented 3 months ago

this was implemented!