Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose macros config in babel #2249

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

NullVoxPopuli
Copy link
Collaborator

@NullVoxPopuli NullVoxPopuli commented Feb 4, 2025

@embroider/macros were not configurable in main/vite before this change.

Proposed way of configuring macros is similar to how we've been doing so in ember-cli-build.js

For example, in the babel config:

const {
  babelCompatSupport,
  templateCompatSupport,
} = require("@embroider/compat/babel");

module.exports = {
  plugins: [
   // ... 
    ...babelCompatSupport({
      '@embroider/macros': {
        setOwnConfig: {},
        setConfig: {
          'library-name': {}
        },
      }
    }),
  ],
  // ...
};

However, this doesn't solve the problem of configuring macros for the minimal app over in #2205

For the minimal app blueprint, we'd have folks do this in their babel config:

const {
  babelCompatSupport,
  templateCompatSupport,
} = require("@embroider/compat/babel");

const { MacrosConfig } = require('@embroider/macros/src/macros-config');

let root = process.cwd();
let macros = MacrosConfig.for({}, root);
let { plugins: templateMacros, setConfig } = MacrosConfig.transforms();

setConfig(macros);

macros.setOwnConfig(root, { /* ... */ });
macros.setConfig(root, 'library-a', { /* ... */ });
macros.setConfig(root, 'library-b', { /* ... */ });

if (process.env.NODE_ENV === 'development') {
  macros.enablePackageDevelopment(process.cwd());
  macros.enableRuntimeMode();
}

macros.finalize();


module.exports = {
  plugins: [
    [
      "babel-plugin-ember-template-compilation",
      {
        compilerPath: "ember-source/dist/ember-template-compiler.js",
        transforms: [...templateMacros],
      },
    ],

   // ... 
   macros.babelPluginConfig();
  ],
  // ...
};

which.... could be better...

So.... I've done added to macros to allow for:

const { buildMacros } = require('@embroider/macros/babel'); 

const macros = buildMacros({
  // this is how you configure your own package
  setOwnConfig: {
    // your config goes here
  },
  // this is how you can optionally send configuration into your
  // dependencies, if those dependencies choose to use
  // @embroider/macros configs.
  setConfig: {
    'some-dependency': {
      // config for some-dependency
    },
  },
});

module.exports = {
  plugins: [
   // ... 
    [
      "babel-plugin-ember-template-compilation",
      {
        compilerPath: "ember-source/dist/ember-template-compiler.js",
        transforms: [...macros.templateMacros],
      },
    ],
    ...macros.babelMacros,
  ],
  // ...
};

Which should be nice for the minimal blueprint in #2205

@NullVoxPopuli NullVoxPopuli self-assigned this Feb 5, 2025
@NullVoxPopuli NullVoxPopuli added the enhancement New feature or request label Feb 5, 2025
@NullVoxPopuli NullVoxPopuli marked this pull request as ready for review February 5, 2025 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant