Archived
1
0
This repository has been archived on 2023-05-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
home-page/node_modules/@pmmmwh/react-refresh-webpack-plugin/lib/runtime/RefreshRuntimeModule.js
Sean Edmunds 0584430b5c First commit
2021-12-13 17:00:40 -06:00

43 lines
1.4 KiB
JavaScript

const RuntimeGlobals = require('webpack/lib/RuntimeGlobals');
const RuntimeModule = require('webpack/lib/RuntimeModule');
const Template = require('webpack/lib/Template');
const { refreshGlobal } = require('../globals');
const getRefreshGlobal = require('../utils/getRefreshGlobal');
class ReactRefreshRuntimeModule extends RuntimeModule {
constructor() {
// Second argument is the `stage` for this runtime module -
// we'll use the same stage as Webpack's HMR runtime module for safety.
super('react refresh', 5);
}
/**
* @returns {string} runtime code
*/
generate() {
const { runtimeTemplate } = this.compilation;
return Template.asString([
`${RuntimeGlobals.interceptModuleExecution}.push(${runtimeTemplate.basicFunction('options', [
`${runtimeTemplate.supportsConst() ? 'const' : 'var'} originalFactory = options.factory;`,
`options.factory = ${runtimeTemplate.basicFunction(
'moduleObject, moduleExports, webpackRequire',
[
`${refreshGlobal}.init();`,
'try {',
Template.indent(
'originalFactory.call(this, moduleObject, moduleExports, webpackRequire);'
),
'} finally {',
Template.indent(`${refreshGlobal}.cleanup(options.id);`),
'}',
]
)}`,
])})`,
'',
getRefreshGlobal(runtimeTemplate),
]);
}
}
module.exports = ReactRefreshRuntimeModule;