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

Stop using require to load initializers, pass the modules instead #305

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

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);

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.

1 participant