Skip to content

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

Closed
BlueCutOfficial wants to merge 1 commit into
ember-cli:masterfrom
BlueCutOfficial:no-require
Closed

Stop using require to load initializers, pass the modules instead#305
BlueCutOfficial wants to merge 1 commit into
ember-cli:masterfrom
BlueCutOfficial:no-require

Conversation

@BlueCutOfficial

@BlueCutOfficial BlueCutOfficial commented Jun 27, 2024

Copy link
Copy Markdown

📝 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

ef4 commented Sep 25, 2024

Copy link
Copy Markdown
Contributor

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