feat: virtual css modules
TODO: fix naming error
This commit is contained in:
parent
6066b58c3d
commit
dc84df3388
20
src/index.ts
20
src/index.ts
@ -106,10 +106,30 @@ const postCSSPlugin = ({
|
||||
await writeFile(tmpFilePath, result.css);
|
||||
|
||||
return {
|
||||
namespace: isModule ? "postcss-module" : "file",
|
||||
path: tmpFilePath
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
// load css modules
|
||||
build.onLoad(
|
||||
{ filter: /.*/, namespace: "postcss-module" },
|
||||
async (args) => {
|
||||
const mod = modulesMap.find(({ path }) => path === args.path),
|
||||
resolveDir = path.dirname(args.path);
|
||||
|
||||
console.log(mod);
|
||||
|
||||
return {
|
||||
resolveDir,
|
||||
contents: `import "${args.path.replace(
|
||||
resolveDir,
|
||||
"."
|
||||
)}"; export default ${JSON.stringify(mod.map)};`
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -20,6 +20,14 @@ describe("PostCSS esbuild tests", () => {
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
it("Works with CSS modules", (done) => {
|
||||
test("modules")
|
||||
.then((res) => {
|
||||
assert(res);
|
||||
done();
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
function test(test) {
|
||||
|
||||
3
test/styles/example.module.css
Normal file
3
test/styles/example.module.css
Normal file
@ -0,0 +1,3 @@
|
||||
.TestModule {
|
||||
align-items: center;
|
||||
}
|
||||
2
test/styles/example.module.sass
Normal file
2
test/styles/example.module.sass
Normal file
@ -0,0 +1,2 @@
|
||||
.TestModuleSass
|
||||
display: flex
|
||||
4
test/tests/modules.ts
Normal file
4
test/tests/modules.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import styles from "../styles/example.module.sass";
|
||||
import styles2 from "../styles/example.module.css";
|
||||
|
||||
console.log(styles, styles2);
|
||||
Loading…
x
Reference in New Issue
Block a user