Skip to content

Conversation

@BlueCutOfficial
Copy link

@BlueCutOfficial BlueCutOfficial commented Jun 27, 2024

📝 This is a draft PR to stop using require to load initializers, it proposes an implementation but if we want to merge it at some point we'll also have to clean up the types.

Context: This PR was drafted in the context of the Embroider Initiative. At some point, we thought we would need it to support initializers when building with Embroider + Vite. It turns out we didn't have to go that far to get initializers work, but this PR can still be interesting in the context of Strict ES Module Support RFC.

How to use: The idea is to pass the app modules to the loadInitializers function directly, with a new argument compatModules. The app.js file of an Ember app would look like this:

// my-ember-app/app/app.js
import compatModules from '@embroider/core/entrypoint';

// Define modules imported from Embroider internals
let d = window.define;
for (const [name, module] of Object.entries(compatModules)) {
  d(name, function () {
    return module;
  });
}

export default class App extends Application { /* modulePrefix = ... */ }

// Pass modules to loadInitializers
loadInitializers(App, config.modulePrefix, compatModules);

@ef4
Copy link
Contributor

ef4 commented Sep 25, 2024

This work is now landing in #306. 👍

@ef4 ef4 closed this Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants