Skip to content

Commit a9e948e

Browse files
committed
fix: move PostCSS config into gulpfile
1 parent b7ae2ce commit a9e948e

File tree

2 files changed

+20
-38
lines changed

2 files changed

+20
-38
lines changed

gulpfile.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
getExtensionAPI,
1414
} from "./src/build/utils";
1515

16+
import * as purgecss from "@fullhuman/postcss-purgecss";
17+
1618
const gulp = require("gulp");
1719
const postcss = require("gulp-postcss");
1820
const fs = require("node:fs");
@@ -73,11 +75,7 @@ gulp.task("build general pages", () => {
7375
})
7476
.pipe(through.obj((file, _, cb) => { // change to .html extension
7577
if (file.isBuffer()) {
76-
const fp = path.format({
77-
dir: path.dirname(file.path),
78-
name: path.basename(file.path, ".hbs"),
79-
ext: '.html'
80-
})
78+
file.path = file.path.replace(".hbs", ".html")
8179
}
8280
cb(null, file);
8381
}))
@@ -120,19 +118,30 @@ gulp.task("collect product icons", () => {
120118
});
121119

122120
gulp.task("build css", async () => {
121+
const purgecssConf = purgecss.default({
122+
content: ["./src/**/*.hbs", "./src/**/*.js", "./src/**/*.ts", "./gulpfile.ts"],
123+
defaultExtractor: (content) => content.match(/[\w-/:]+(?<!:)/g) || [],
124+
});
125+
const plugins = [
126+
require("postcss-import"),
127+
require("tailwindcss")("tailwind.config.js"),
128+
require("autoprefixer"),
129+
...(process.env.NODE_ENV === "production" ? [purgecssConf] : []),
130+
];
131+
123132
return gulp
124133
.src(["./src/static/css/base.scss"])
125-
.pipe(postcss())
134+
.pipe(postcss(plugins, {
135+
syntax: require("postcss-scss")
136+
}))
137+
.on("error", (err) => console.error(err))
126138
.pipe(through.obj((file, _, cb) => { // change to .css extension
127139
if (file.isBuffer()) {
128-
const fp = path.format({
129-
dir: path.dirname(file.path),
130-
name: path.basename(file.path, ".scss"),
131-
ext: '.css'
132-
})
140+
file.path = file.path.replace(".scss", ".css")
133141
}
134142
cb(null, file);
135143
}))
144+
.on("error", (err) => console.error(err))
136145
.pipe(gulp.dest("./dist/static/css/"));
137146
});
138147

postcss.config.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)