-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportStyle.js
45 lines (43 loc) · 1.33 KB
/
exportStyle.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sass from 'sass';
import postcss from 'postcss';
import prefixer from 'postcss-prefixer';
import fs from 'node:fs/promises';
import path from 'node:path';
import base64 from 'postcss-base64';
const entryPoint = [
{
output: 'entry/entry-modal.css',
file: './src/styles/entry/index.scss',
},
{
output: 'line/entry-modal.css',
file: './src/styles/line/index.scss',
},
];
entryPoint.forEach(({ file, output }) => {
sass.render(
{
file,
},
async function (err, result) {
if (err) {
console.error(err);
} else {
const content = result.css.toString();
const parsingContent = await postcss([
prefixer({
prefix: 'entry-modal-',
}),
base64({
root: './src/styles/assets',
extensions: ['.png', '.svg'],
}),
]).process(content);
const outputPath = path.join('.', 'dist', output);
const parser = path.parse(outputPath);
await fs.mkdir(parser.dir, { recursive: true });
await fs.writeFile(path.join('.', 'dist', output), parsingContent.css);
}
}
);
});