Skip to content

Commit 44bbcfe

Browse files
committed
fix(runtime-generator): fix module not found errors for custom spriteModule or symbolModule
This change fixes module not found errors that could occur when specifying a custom spriteModule or symbolModule. Previously the import statements this loader generated would only work for svg imports made from certain directories.
1 parent 48b1921 commit 44bbcfe

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/runtime-generator.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { isAbsolute, join } = require('path');
12
const { stringifyRequest } = require('loader-utils');
23
const {
34
stringify,
@@ -16,7 +17,7 @@ const {
1617
* @return {string}
1718
*/
1819
function runtimeGenerator(params) {
19-
const { symbol, config, context } = params;
20+
const { symbol, config, context, loaderContext } = params;
2021
const { extract, esModule, spriteModule, symbolModule, runtimeCompat, publicPath } = config;
2122
let runtime;
2223

@@ -33,8 +34,11 @@ function runtimeGenerator(params) {
3334
}`;
3435
runtime = generateExport(data, esModule);
3536
} else {
36-
const spriteModuleImport = stringifyRequest({ context }, spriteModule);
37-
const symbolModuleImport = stringifyRequest({ context }, symbolModule);
37+
const spriteModuleAbsPath = isAbsolute(spriteModule) ? spriteModule : join(context, spriteModule);
38+
const symbolModuleAbsPath = isAbsolute(symbolModule) ? symbolModule : join(context, symbolModule);
39+
40+
const spriteModuleImport = stringifyRequest(loaderContext, spriteModuleAbsPath);
41+
const symbolModuleImport = stringifyRequest(loaderContext, symbolModuleAbsPath);
3842

3943
runtime = [
4044
generateImport('SpriteSymbol', symbolModuleImport, esModule),

0 commit comments

Comments
 (0)