Skip to content

Commit

Permalink
fix: postCSS reference path
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-capsule42 committed Jan 2, 2025
1 parent 5168ea5 commit 6d33791
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions scripts/build/postCss.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
/* eslint-disable brace-style, eqeqeq, object-property-newline, arrow-parens, array-element-newline, object-shorthand, dot-location, no-use-before-define, prefer-template, consistent-return, no-underscore-dangle, prefer-arrow-callback */

import autoprefixer from 'autoprefixer';
import postcss from 'postcss';
import comments from 'postcss-discard-comments';
import path from 'path';
import fs from 'fs';
import process from 'process';

const __dirname = new URL('.', import.meta.url).pathname;
const directoryPath = path.join(__dirname, '../src');
const __dirname = process.cwd();
const directoryPath = path.join(__dirname, '/src');

/**
* Default postCSS run
* Locates all CSS files within the directory and loop
* through the standardProcessor() function.
*/
fs.readdir(directoryPath, function (err, files) {
//handling error
// handling error
if (err) {
return console.log('Unable to scan directory: ' + err);
return console.log('Unable to scan directory: ' + err); // eslint-disable-line no-console
}
//listing all files using forEach
// listing all files using forEach
files.forEach(function (file) {
if (file.includes(".css")) {
standardProcessor(file);
Expand All @@ -28,19 +31,19 @@ fs.readdir(directoryPath, function (err, files) {
/**
* The standardProcessor function applies tokens for fallback selectors
* and completes a post cleanup.
* @param {string} file
* @param {string} file - The file to process.
*/
function standardProcessor(file) {
fs.readFile(`src/${file}`, (err, css) => {
postcss([autoprefixer, comments])
.use(comments({
remove: function(comment) { return comment[0] == "@"; }
}))
.process(css, { from: `src/${file}`, to: `src/${file}` })
.then(result => {
fs.writeFile(`src/${file}`, result.css, () => true)
})
});
fs.readFile(`src/${file}`, (err, css) => {
postcss([autoprefixer, comments])
.use(comments({
remove: function(comment) { return comment[0] == "@"; }
}))
.process(css, { from: `src/${file}`, to: `src/${file}` })
.then(result => {
fs.writeFile(`src/${file}`, result.css, () => true);
});
});
}

/**
Expand All @@ -60,4 +63,4 @@ function standardProcessor(file) {
// fs.writeFile('src/style.map', result.map, () => true)
// }
// })
// });
// });

0 comments on commit 6d33791

Please sign in to comment.