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

Resolve FastBoot dependencies at compile time #493

Closed
wants to merge 1 commit into from

Conversation

bobisjan
Copy link
Contributor

@bobisjan bobisjan commented Apr 10, 2020

This change makes FastBoot dependencies required at compile time, hence no need to cd dist && npm install as before. It somehow aligns with ember-auto-import, when app imports modules from 3rd packages, then EAI bundles these modules at compile time. I assume that this will be improved with Embroider in the future.

This change makes FastBoot dependencies required at compile time, hence no need to `cd dist && npm install` as before.
}
}), 'node-fetch');

fetchNode = debug(map(fetchNode, (content) => `define('node-fetch', ['exports'], function(exports) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if there is a better way to do this?

@ef4
Copy link
Contributor

ef4 commented Apr 13, 2020

While I agree with the high-level goal here, I don't think this code belongs in individual addons like ember-fetch. I see from your comment on fastboot that you already understand the need to fix this upstream and see this as a temporary step. In general, adding a whole new build pipeline (rollup in this case) to an addon makes it harder for us to control and optimize the whole build, so I usually discourage it.

You could work around this in your own app instead, with the bundling handled by ember-auto-import, something like this:

// app/routes/application.js
...
fastboot: service(),
async beforeModel() {
  if (this.fastboot.isFastboot) {
     // we're choosing not to use Fastboot.require because we want all dependencies to get
     // bundled at build time instead. So here we provide the dependencies that addons would
     // have tried to Fastboot.require.
     let dependencies = await Promise.all([
       import('node-fetch'),
       import('abortcontroller-polyfill/dist/cjs-ponyfill'),
     ]);
     Fastboot.require = function(which) {
        switch (which) {
           case 'node-fetch':
              return dependencies[0].default;
           case 'abortcontroller-polyfill/dist/cjs-ponyfill':
              return dependencies[1].default;
           default:
              throw new Error(`we did not bundle: ${which}`);
        }
     }
  }
}
...

In this case, ember-auto-import will always see and bundle the dependencies but they will go into their own lazy chunk(s) that never load in the browser.

@bobisjan
Copy link
Contributor Author

bobisjan commented Jul 5, 2022

Closing in favour of #656 (comment)

@bobisjan bobisjan closed this Jul 5, 2022
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