From f3ff661f9d40693c836427ec0a5e7b43e64544cf Mon Sep 17 00:00:00 2001 From: "lili.21" Date: Fri, 10 Dec 2021 13:55:29 +0800 Subject: [PATCH] fix: handle virtual module fix #307 --- src/index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 477026b..bd2f927 100644 --- a/src/index.js +++ b/src/index.js @@ -119,12 +119,17 @@ export default ({ const getTargetResourcePath = (path: *, stats: *) => { const targetFileDirectoryPath = dirname(stats.file.opts.filename); + try { + if (path.node.source.value.startsWith('.')) { + return resolve(targetFileDirectoryPath, path.node.source.value); + } - if (path.node.source.value.startsWith('.')) { + return require.resolve(path.node.source.value); + } catch (_) { + // virtual module return resolve(targetFileDirectoryPath, path.node.source.value); } - - return require.resolve(path.node.source.value); + }; const isFilenameExcluded = (filename, exclude) => {