forked from orangehrm/oxd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite-plugin-collect-scss.ts
More file actions
30 lines (27 loc) · 890 Bytes
/
Copy pathvite-plugin-collect-scss.ts
File metadata and controls
30 lines (27 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import path from 'path';
import fs from 'node:fs';
function cleanReadFiles(path: string) {
const source = fs.readFileSync(path, 'utf-8');
// remove comments
return source.replace(/\/\*[\s\S]*?\*\/|\/\/.*/gm, '').trim();
}
export default function collectSass() {
const varFiles: string[] = [];
const varOutput = path.resolve(__dirname, 'dist/variables.scss');
return {
name: 'collect-sass',
buildStart() {
[
path.resolve(__dirname, 'src/styles/_colors.scss'),
path.resolve(__dirname, 'src/styles/_mixins.scss'),
path.resolve(__dirname, 'src/styles/_variables.scss'),
].map((_file) => {
varFiles.push(cleanReadFiles(_file));
});
},
async generateBundle() {
await fs.promises.mkdir(path.dirname(varOutput), {recursive: true});
await fs.promises.writeFile(varOutput, varFiles.join(''));
},
};
}