From 5a079171e01cee7bc9ddb42c057a21a484927435 Mon Sep 17 00:00:00 2001 From: Nikolai Mavrenkov Date: Mon, 22 Jan 2024 01:44:59 +0200 Subject: [PATCH] Always use dir name relative to root to make it work with other plugins --- index.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/index.ts b/index.ts index daaa710..9069a05 100644 --- a/index.ts +++ b/index.ts @@ -30,14 +30,11 @@ export = (options: Options = {}): Plugin => ({ name: "css-modules", setup: function (build) { const { extension = ".module.css", localIdentName = "[hash]" } = options; - const rootDir = process.cwd(); const filter = new RegExp(`.\/.+${extension.replace(/\./g, "\\.")}$`); const tmpDirPath = tmp.dirSync().name; build.onLoad({ filter }, async (args) => { - const relativeDir = path.relative(rootDir, path.dirname(args.path)); - const fileContent = (await readFile(args.path)) as Buffer; const baseName = path.basename(args.path, extension); @@ -117,7 +114,7 @@ export = (options: Options = {}): Plugin => ({ const baseFileName = path.basename(args.path, extension); const tmpFilePath = path.resolve( tmpDirPath, - relativeDir, + path.relative("/", path.dirname(args.path)), `${baseFileName}.css` );