Skip to content

Commit

Permalink
Always use dir name relative to root to make it work with other plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
koluch committed Jan 21, 2024
1 parent 6f27c57 commit 5a07917
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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`
);

Expand Down

0 comments on commit 5a07917

Please sign in to comment.