-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-css.cjs
More file actions
58 lines (52 loc) · 1.42 KB
/
build-css.cjs
File metadata and controls
58 lines (52 loc) · 1.42 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
const fs = require('node:fs');
const esbuild = require('esbuild');
const postCssPlugin = require('esbuild-style-plugin');
const BASE_DIRECTORY = 'src';
const entryPoints = fs
.readdirSync(BASE_DIRECTORY, { recursive: true })
.filter((path) => path.endsWith('.css'))
.map((path) => `src/${path}`);
const BUILD_OPTIONS = {
entryPoints: entryPoints,
outdir: 'build',
bundle: true,
minify: process.env.NODE_ENV !== 'production' ? false : true,
entryNames: '[dir]/[name]',
outbase: BASE_DIRECTORY,
packages: 'external',
outExtension: { '.js': '.EMPTY' },
plugins: [
postCssPlugin({
extract: true,
postcss: {
plugins: [require('postcss-import'), require('tailwindcss/nesting'), require('tailwindcss'), require('autoprefixer')],
},
}),
],
};
console.log(`Build CSS for ${entryPoints.join(' and\n\t')}`);
const args = process.argv.slice(2);
if (args.includes('--watch')) {
esbuild
.context(BUILD_OPTIONS)
.then((ctx) => {
ctx
.watch()
.then(() => {
console.log('watching for css file changes...');
})
.catch((reason) => {
console.error(`Watch failed: ${reason}`);
process.exit(1);
});
})
.catch(() => {
console.error(`Build error: ${error}`);
process.exit(1);
});
} else {
esbuild.build(BUILD_OPTIONS).catch(() => {
console.error(`Build error: ${error}`);
process.exit(1);
});
}