fied require problem in webpacked app

This commit is contained in:
Jan Prochazka
2020-11-26 15:42:50 +01:00
parent d7ceb297e9
commit 3533683a32
5 changed files with 28 additions and 400 deletions

View File

@@ -12,8 +12,16 @@ function requirePlugin(packageName, requiredPlugin = null) {
if (loadedPlugins[packageName]) return loadedPlugins[packageName];
if (requiredPlugin == null) {
console.log('Loading module', packageName);
const module = require(path.join(pluginsdir(), packageName, 'dist', 'backend.js'));
let module;
const modulePath = path.join(pluginsdir(), packageName, 'dist', 'backend.js');
console.log(`Loading module ${packageName} from ${modulePath}`);
try {
// @ts-ignore
module = __non_webpack_require__(modulePath);
} catch (err) {
console.error('Failed load webpacked module', err);
module = require(modulePath);
}
requiredPlugin = module.__esModule ? module.default : module;
}
loadedPlugins[packageName] = requiredPlugin;