1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 08:27:42 +02:00

fix: importing extA lazy module from extB

This commit is contained in:
Sami Mazouz
2024-11-09 11:01:36 +01:00
parent 820894a7c9
commit dd45d75cd8
2 changed files with 19 additions and 14 deletions

View File

@@ -2,12 +2,17 @@
* This plugin overrides the webpack chunk loader function `__webpack_require__.l` which is a webpack constant
* with `flarum.reg.loadChunk`, which resides in the flarum app.
*/
const path = require('path');
const extensionId = require('./extensionId.cjs');
class OverrideChunkLoaderFunction {
apply(compiler) {
const thisComposerJson = require(path.resolve(process.cwd(), '../composer.json'));
const namespace = extensionId(thisComposerJson.name);
// We don't want to literally override its source.
// We want to override the function that is called by webpack.
// By adding a new line to reassing the function to our own function.
// By adding a new line to reassign the function to our own function.
// The function is called by webpack so we can't just override it.
compiler.hooks.compilation.tap('OverrideChunkLoaderFunction', (compilation) => {
compilation.mainTemplate.hooks.requireEnsure.tap('OverrideChunkLoaderFunction', (source) => {
@@ -16,6 +21,13 @@ class OverrideChunkLoaderFunction {
'\nconst originalLoadChunk = __webpack_require__.l;\n__webpack_require__.l = flarum.reg.loadChunk.bind(flarum.reg, originalLoadChunk);'
);
});
// log webpack runtime after the final code, the hook isn't requireEnsure
if (namespace !== 'core') {
compilation.mainTemplate.hooks.require.tap('OverrideChunkLoaderFunction', (source) => {
return 'flarum.reg._webpack_runtimes["' + namespace + '"] ||= __webpack_require__;' + source;
});
}
});
}
}