Fix to resolve entry points

This commit is contained in:
g45t345rt 2021-03-23 19:23:06 -04:00
parent 68340d405f
commit a842d7daa5
3 changed files with 25 additions and 12 deletions

View File

@ -56,8 +56,10 @@ const postCSSPlugin = ({
}); });
build.onResolve( build.onResolve(
{ filter: /.\.(css|sass|scss|less|styl)$/, namespace: "file" }, { filter: /.\.(css|sass|scss|less|styl)$/ },
async (args) => { async (args) => {
if (args.namespace !== "file" && args.namespace !== "") return;
const sourceFullPath = path.resolve(args.resolveDir, args.path), const sourceFullPath = path.resolve(args.resolveDir, args.path),
sourceExt = path.extname(sourceFullPath), sourceExt = path.extname(sourceFullPath),
sourceBaseName = path.basename(sourceFullPath, sourceExt), sourceBaseName = path.basename(sourceFullPath, sourceExt),
@ -65,13 +67,10 @@ const postCSSPlugin = ({
sourceRelDir = path.relative(path.dirname(rootDir), sourceDir), sourceRelDir = path.relative(path.dirname(rootDir), sourceDir),
isModule = sourceBaseName.match(/\.module$/), isModule = sourceBaseName.match(/\.module$/),
tmpDir = path.resolve(tmpDirPath, sourceRelDir), tmpDir = path.resolve(tmpDirPath, sourceRelDir),
tmpFilePath = path.resolve( tmpFilePath = path.resolve(tmpDir, `${sourceBaseName}.css`);
tmpDir,
`${sourceBaseName}-tmp-${Date.now()}-${sourceExt.replace(".", "")}${
isModule ? ".module" : ""
}.css`
);
console.log(tmpDir);
console.log(tmpFilePath);
await ensureDir(tmpDir); await ensureDir(tmpDir);
const fileContent = await readFile(sourceFullPath); const fileContent = await readFile(sourceFullPath);

View File

@ -5,7 +5,7 @@ const autoprefixer = require("autoprefixer"),
describe("PostCSS esbuild tests", () => { describe("PostCSS esbuild tests", () => {
it("Works with basic CSS imports", (done) => { it("Works with basic CSS imports", (done) => {
test("basic") test("tests/basic.ts")
.then((res) => { .then((res) => {
assert(res); assert(res);
done(); done();
@ -13,7 +13,7 @@ describe("PostCSS esbuild tests", () => {
.catch(done); .catch(done);
}); });
it("Works with preprocessors", (done) => { it("Works with preprocessors", (done) => {
test("preprocessors") test("tests/preprocessors.ts")
.then((res) => { .then((res) => {
assert(res); assert(res);
done(); done();
@ -21,7 +21,15 @@ describe("PostCSS esbuild tests", () => {
.catch(done); .catch(done);
}); });
it("Works with CSS modules", (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) => { .then((res) => {
assert(res); assert(res);
done(); done();
@ -30,9 +38,9 @@ describe("PostCSS esbuild tests", () => {
}); });
}); });
function test(test) { function test(entryPoint) {
return build({ return build({
entryPoints: [`tests/${test}.ts`], entryPoints: [entryPoint],
bundle: true, bundle: true,
outdir: "dist", outdir: "dist",
plugins: [ plugins: [

6
test/tests/styles.css Normal file
View File

@ -0,0 +1,6 @@
.example {
display: grid;
transition: all 0.5s;
user-select: none;
background: linear-gradient(to bottom, white, black);
}