| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
This PR updates @sdinteractive/requirejs-export-plugin to work with webpack 5 (Magento 2.4.8-p5), addressing the runtime ReferenceError: module is not defined by changing how module exports are captured and exposed to RequireJS.
Changes:
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| package.json | Version bump and description update to indicate webpack 5 support. |
| index.js | Implement webpack 5-compatible export capture and asset wrapping, while retaining webpack 4 behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
| compilation.hooks.chunkAsset.tap('RequireJsExportPlugin', (chunk, filename) => { | ||
| const modules = chunk.modulesIterable ? Array.from(chunk.modulesIterable) : []; | ||
| const needsImport = gatherRequireJsImports(modules); | ||
| const needsExport = gatherRequireJsExports(modules); | ||
|
|
| if (shouldExport(module) && module._source) { | ||
| const definition = '__webpack_exports__[' + JSON.stringify(module.id) + '] = module.exports;'; | ||
| module._source = new ConcatSource(module._source, '\n', definition); |
| window.define(${jsonName}, ${jsonDefineStubs}, function () { | ||
| var exp = __requirejs_exports__[${jsonId}]; | ||
| return (exp && exp.__esModule && exp.default) ? exp.default : exp; | ||
| });`; |
| ) | ||
| .join('\n'); | ||
|
|
||
| const prolog = generateProlog(chunk.id, needsImport, needsExport); |
| compiler.options.output = compiler.options.output || {}; | ||
| compiler.options.output.iife = false; |
| for (const filename of chunk.files) { | ||
| compilation.updateAsset( | ||
| filename, | ||
| (old) => new ConcatSource(prolog, '\n', old, '\n', captureCode, '\n', epilog) | ||
| ); | ||
| } |
| const captureCode = needsExport | ||
| .map(({ id }) => | ||
| ` try { __requirejs_exports__[${JSON.stringify(id)}] = __webpack_require__(${JSON.stringify(id)}); } catch(e) {}` | ||
| ) | ||
| .join('\n'); |
| Back | FazBrowse Home | New Git URL |
Goal of this PR is to fix on the magento 2.4.8-p5 upgrade
ReferenceError: module is not defined