diff --git a/gulpfile.ts b/gulpfile.ts index 7b83d660..d76c5b27 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -13,6 +13,8 @@ import { getExtensionAPI, } from "./src/build/utils"; +import * as purgecss from "@fullhuman/postcss-purgecss"; + const gulp = require("gulp"); const postcss = require("gulp-postcss"); const fs = require("node:fs"); @@ -73,11 +75,7 @@ gulp.task("build general pages", () => { }) .pipe(through.obj((file, _, cb) => { // change to .html extension if (file.isBuffer()) { - const fp = path.format({ - dir: path.dirname(file.path), - name: path.basename(file.path, ".hbs"), - ext: '.html' - }) + file.path = file.path.replace(".hbs", ".html") } cb(null, file); })) @@ -120,19 +118,30 @@ gulp.task("collect product icons", () => { }); gulp.task("build css", async () => { + const purgecssConf = purgecss.default({ + content: ["./src/**/*.hbs", "./src/**/*.js", "./src/**/*.ts", "./gulpfile.ts"], + defaultExtractor: (content) => content.match(/[\w-/:]+(? console.error(err)) .pipe(through.obj((file, _, cb) => { // change to .css extension if (file.isBuffer()) { - const fp = path.format({ - dir: path.dirname(file.path), - name: path.basename(file.path, ".scss"), - ext: '.css' - }) + file.path = file.path.replace(".scss", ".css") } cb(null, file); })) + .on("error", (err) => console.error(err)) .pipe(gulp.dest("./dist/static/css/")); }); diff --git a/postcss.config.js b/postcss.config.js deleted file mode 100644 index 58fb5190..00000000 --- a/postcss.config.js +++ /dev/null @@ -1,27 +0,0 @@ -const purgecss = require('@fullhuman/postcss-purgecss')({ - // Specify the paths to all of the template files in your project - content: ["./src/**/*.hbs", "./src/**/*.js", "./src/**/*.ts", "./gulpfile.ts"], - - // This is the function used to extract class names from your templates - defaultExtractor: content => { - // Capture as liberally as possible, including things like `h-(screen-1.5)` - const broadMatches = content.match(/[^<>"'`\s]*[^<>"'`\s:]/g) || [] - - // Capture classes within other delimiters like .block(class="w-1/2") in Pug - const innerMatches = content.match(/[^<>"'`\s.()]*[^<>"'`\s.():]/g) || [] - - return broadMatches.concat(innerMatches) - } -}); - -module.exports = { - plugins: [ - require("postcss-import"), - require("tailwindcss")("tailwind.config.js"), - require("autoprefixer"), - ...process.env.NODE_ENV === 'production' - ? [purgecss] - : [] - ], - syntax: require("postcss-scss") -}