diff --git a/src/index.ts b/src/index.ts index 3a0e342..5393e33 100644 --- a/src/index.ts +++ b/src/index.ts @@ -56,8 +56,10 @@ const postCSSPlugin = ({ }); build.onResolve( - { filter: /.\.(css|sass|scss|less|styl)$/, namespace: "file" }, + { filter: /.\.(css|sass|scss|less|styl)$/ }, async (args) => { + if (args.namespace !== "file" && args.namespace !== "") return; + const sourceFullPath = path.resolve(args.resolveDir, args.path), sourceExt = path.extname(sourceFullPath), sourceBaseName = path.basename(sourceFullPath, sourceExt), @@ -65,13 +67,10 @@ const postCSSPlugin = ({ sourceRelDir = path.relative(path.dirname(rootDir), sourceDir), isModule = sourceBaseName.match(/\.module$/), tmpDir = path.resolve(tmpDirPath, sourceRelDir), - tmpFilePath = path.resolve( - tmpDir, - `${sourceBaseName}-tmp-${Date.now()}-${sourceExt.replace(".", "")}${ - isModule ? ".module" : "" - }.css` - ); + tmpFilePath = path.resolve(tmpDir, `${sourceBaseName}.css`); + console.log(tmpDir); + console.log(tmpFilePath); await ensureDir(tmpDir); const fileContent = await readFile(sourceFullPath); diff --git a/test/index.js b/test/index.js index 297f39f..6e980ef 100644 --- a/test/index.js +++ b/test/index.js @@ -5,7 +5,7 @@ const autoprefixer = require("autoprefixer"), describe("PostCSS esbuild tests", () => { it("Works with basic CSS imports", (done) => { - test("basic") + test("tests/basic.ts") .then((res) => { assert(res); done(); @@ -13,7 +13,7 @@ describe("PostCSS esbuild tests", () => { .catch(done); }); it("Works with preprocessors", (done) => { - test("preprocessors") + test("tests/preprocessors.ts") .then((res) => { assert(res); done(); @@ -21,7 +21,15 @@ describe("PostCSS esbuild tests", () => { .catch(done); }); it("Works with CSS modules", (done) => { - test("modules") + test("tests/modules.ts") + .then((res) => { + assert(res); + done(); + }) + .catch(done); + }); + it("Works with CSS as entrypoint", (done) => { + test("tests/styles.css") .then((res) => { assert(res); done(); @@ -30,9 +38,9 @@ describe("PostCSS esbuild tests", () => { }); }); -function test(test) { +function test(entryPoint) { return build({ - entryPoints: [`tests/${test}.ts`], + entryPoints: [entryPoint], bundle: true, outdir: "dist", plugins: [ diff --git a/test/tests/styles.css b/test/tests/styles.css new file mode 100644 index 0000000..65ec989 --- /dev/null +++ b/test/tests/styles.css @@ -0,0 +1,6 @@ +.example { + display: grid; + transition: all 0.5s; + user-select: none; + background: linear-gradient(to bottom, white, black); +}