-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
escape path separator in lazy loader on windows
- Loading branch information
1 parent
73674db
commit bcb7f5d
Showing
1 changed file
with
11 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`; | ||
}; |