Skip to content

Commit

Permalink
escape path separator in lazy loader on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
DenverCoder544 committed Oct 7, 2024
1 parent 73674db commit bcb7f5d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions webpack/oskariLazyLoader.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
const path = require('path');

module.exports = function (source) {
if (!this.query) {
throw new Error('Param with bundle name must be given, eg. "import \'oskari-lazy-loader?bundlename!path/to/bundle.js\'"');
}
const name = this.query.slice(1);

// resourcePath is the full path from root to file in the disk (atleast on WSL)
const parts = this.resourcePath.split('/node_modules/');
const axe = `${path.sep}node_modules${path.sep}`;
const parts = this.resourcePath.split(axe);

// anything from oskari comes in parts[1], anything from app itself comes from parts[0] -> mobileuserguide in pti
// import 'oskari-lazy-loader?metadatasearch!oskari-frontend/packages/catalogue/metadatasearch/bundle.js';
// -> `oskari-loader!oskari-frontend/packages/catalogue/metadatasearch/bundle.js`
// import 'oskari-lazy-loader?mobileuserguide!../../bundles/paikkatietoikkuna/mobileuserguide/bundle.js';
// -> `oskari-loader!../../bundles/paikkatietoikkuna/mobileuserguide/bundle.js`
const bundlePath = `oskari-loader!${parts.length === 1 ? parts[0] : parts[1]}`;

return `Oskari.bundle_manager.registerDynamic('${name}', function() {return import(/* webpackChunkName: "chunk_${name}" */ '${bundlePath}');});\n`;
let separatorReplaced = bundlePath;
if (path.sep === '\\') {
separatorReplaced = bundlePath.replaceAll(/\\/g, '\\\\');
}
return `Oskari.bundle_manager.registerDynamic('${name}', function() {return import(/* webpackChunkName: "chunk_${name}" */ '${separatorReplaced}');});\n`;
};

0 comments on commit bcb7f5d

Please sign in to comment.