Resolve FastBoot dependencies at compile time#493
Resolve FastBoot dependencies at compile time#493bobisjan wants to merge 1 commit intoember-cli:masterfrom
Conversation
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) { |
There was a problem hiding this comment.
I'm not sure if there is a better way to do this?
|
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. |
|
Closing in favour of #656 (comment) |
This change makes FastBoot dependencies required at compile time, hence no need to
cd dist && npm installas before. It somehow aligns withember-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.