1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- const { getRefreshGlobalScope } = require('../globals');
- const getRefreshGlobal = require('./getRefreshGlobal');
- function makeRefreshRuntimeModule(webpack) {
- return class ReactRefreshRuntimeModule extends webpack.RuntimeModule {
- constructor() {
-
-
- super('react refresh', webpack.RuntimeModule.STAGE_BASIC);
- }
-
- generate() {
- const { runtimeTemplate } = this.compilation;
- const refreshGlobal = getRefreshGlobalScope(webpack.RuntimeGlobals);
- return webpack.Template.asString([
- `${webpack.RuntimeGlobals.interceptModuleExecution}.push(${runtimeTemplate.basicFunction(
- 'options',
- [
- `${
- runtimeTemplate.supportsConst() ? 'const' : 'var'
- } originalFactory = options.factory;`,
- `options.factory = function (moduleObject, moduleExports, webpackRequire) {`,
- webpack.Template.indent([
- `${refreshGlobal}.setup(options.id);`,
- 'try {',
- webpack.Template.indent(
- 'originalFactory.call(this, moduleObject, moduleExports, webpackRequire);'
- ),
- '} finally {',
- webpack.Template.indent([
- `if (typeof Promise !== 'undefined' && moduleObject.exports instanceof Promise) {`,
- webpack.Template.indent([
-
-
-
-
-
-
-
- 'options.module.exports = options.module.exports.then(',
- webpack.Template.indent([
- `${runtimeTemplate.basicFunction('result', [
- `${refreshGlobal}.cleanup(options.id);`,
- 'return result;',
- ])},`,
- runtimeTemplate.basicFunction('reason', [
- `${refreshGlobal}.cleanup(options.id);`,
- 'return Promise.reject(reason);',
- ]),
- ]),
- `);`,
- ]),
- '} else {',
- webpack.Template.indent(`${refreshGlobal}.cleanup(options.id)`),
- '}',
- ]),
- '}',
- ]),
- `};`,
- ]
- )})`,
- '',
- getRefreshGlobal(webpack.Template, webpack.RuntimeGlobals, runtimeTemplate),
- ]);
- }
- };
- }
- module.exports = makeRefreshRuntimeModule;
|