Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

escape path separator in lazy loader on windows #2684

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`;
};
Loading