mirror of
https://github.com/flarum/framework.git
synced 2025-02-17 02:02:47 +08:00
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
// Hi early reviewer! I'm a temporary file and
|
|
// will be moved to the Flarum webpack config soon!
|
|
|
|
const loaderUtils = require('loader-utils');
|
|
|
|
// Custom loader logic
|
|
module.exports = function (source) {
|
|
|
|
// Get the type of the module to be exported
|
|
const location = loaderUtils.interpolateName(this, '[folder]/', {
|
|
context: this.rootContext || this.context,
|
|
});
|
|
|
|
// Get the name of module to be exported
|
|
const moduleName = loaderUtils.interpolateName(this, '[name]', {
|
|
context: this.rootContext || this.context,
|
|
});
|
|
|
|
// Don't export low level files
|
|
if (/.*\/(admin|forum)$/.test(location) || /(index|app|compat|FlarumRegistry)$/.test(moduleName)) {
|
|
return source;
|
|
}
|
|
|
|
let addition = "";
|
|
|
|
// Find the export names
|
|
const matches = [...source.matchAll(/export\s+?(?:default\s?|function|abstract\s?|class)+?\s([^(\s<;]*)/gm)];
|
|
matches.map(match => {
|
|
let name = match[1]
|
|
|
|
if (!name || name === 'interface') {
|
|
return;
|
|
}
|
|
|
|
// Add code at the end of the file to add the file to registry
|
|
addition += `\nwindow.flreg.add('${location}${name}', ${name})`
|
|
});
|
|
|
|
return source + addition;
|
|
}
|