Skip to content

Commit a3dfedf

Browse files
authored
Improve theming by generating a distinct css file for each theme (#271)
* build separate css file for each theme
1 parent 854e0ec commit a3dfedf

File tree

12 files changed

+76
-22
lines changed

12 files changed

+76
-22
lines changed

examples/src/pages/tests/table/utils/ListRowManager.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const createRow = (node?: string): ListRowInterface => {
1414
getNode: () => node,
1515
destroy: () => {},
1616
onMount: () => {},
17+
isMounted: () => true,
1718
debugId: 'test',
1819
ref: () => {},
1920
};

source/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
"module": "index.mjs",
3131
"typings": "index.d.ts",
3232
"scripts": {
33-
"build": "INFINITE_OUT_FOLDER=${INFINITE_OUT_FOLDER:=$npm_package_config_outdir} npm-run-all -s rm-out-folder tsc esbuild generate-dts-file update-md copy-license-and-readme",
33+
"build": "INFINITE_OUT_FOLDER=${INFINITE_OUT_FOLDER:=$npm_package_config_outdir} npm-run-all -s rm-out-folder tsc esbuild esbuild-theming generate-dts-file update-md copy-license-and-readme",
3434
"rm-out-folder": "rimraf $INFINITE_OUT_FOLDER",
3535
"copy-license-and-readme": "cp LICENSE.md ./$INFINITE_OUT_FOLDER && cp ../README.md ./$INFINITE_OUT_FOLDER",
3636
"watch": "npm run esbuild && npm run generate-dts-file && concurrently \"npm run esbuild-watch\" \"npm run generate-dts-file-watch\"",
3737
"rollup-types": "rollup -c rollup.config.js",
3838
"update-md": "npm run --prefix .. doctoc",
3939
"esbuild": "tsup --config dev-bundle.tsup.config.ts && tsup",
40+
"esbuild-theming": "tsup --config tsup-theming.config.ts",
4041
"esbuild-watch": "tsup --watch",
4142
"esbuild-deepmap": "npm run esbuild-deepmap-esm && npm run esbuild-deepmap-cjs",
4243
"esbuild-deepmap-esm": "node run-build-deepmap.js esm",
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import './theme-default.css';
2-
import './theme-minimalist.css';
3-
import './theme-ocean.css';
4-
import './theme-balsam.css';
5-
import './theme-shadcn.css';
2+
// import './theme-minimalist.css';
3+
// import './theme-ocean.css';
4+
// import './theme-balsam.css';
5+
// import './theme-shadcn.css';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './components/InfiniteTable/theme-balsam.css';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './components/InfiniteTable/theme-default.css';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './components/InfiniteTable/theme-minimalist.css';

source/src/generate-theme-ocean.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './components/InfiniteTable/theme-ocean.css';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './components/InfiniteTable/theme-shadcn.css';

source/tsup-theming.config.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { defineConfig, Options } from 'tsup';
2+
3+
// @ts-ignore
4+
import packageJSON from './package.json';
5+
6+
import fs from 'fs';
7+
8+
import { vanillaConfig } from './tsup-vanilla-extract-config';
9+
10+
const { config } = packageJSON;
11+
const outDir = config.outdir + '/theme/';
12+
13+
export const tsupConfig: Options = {
14+
entry: {
15+
balsam: './src/generate-theme-balsam.ts',
16+
default: './src/generate-theme-default.ts',
17+
minimalist: './src/generate-theme-minimalist.ts',
18+
ocean: './src/generate-theme-ocean.ts',
19+
shadcn: './src/generate-theme-shadcn.ts',
20+
},
21+
22+
tsconfig: './tsconfig.build.json',
23+
outDir,
24+
bundle: true,
25+
clean: false,
26+
27+
onSuccess: async () => {
28+
// remove all non-css files from the theme folder
29+
fs.readdirSync(outDir).forEach((file) => {
30+
if (!file.endsWith('.css')) {
31+
fs.unlinkSync(outDir + '/' + file);
32+
} else {
33+
console.log('Generated ' + file);
34+
}
35+
});
36+
37+
console.log('Files generated in ' + outDir + ' folder');
38+
},
39+
40+
esbuildPlugins: [vanillaConfig],
41+
};
42+
43+
export default defineConfig(tsupConfig);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { vanillaExtractPlugin } from '@vanilla-extract/esbuild-plugin';
2+
3+
import postcss from 'postcss';
4+
import autoprefixer from 'autoprefixer';
5+
6+
async function processCss(css) {
7+
const result = await postcss([autoprefixer]).process(css, {
8+
from: undefined /* suppress source map warning */,
9+
});
10+
11+
return result.css;
12+
}
13+
14+
export const vanillaConfig = vanillaExtractPlugin({
15+
processCss,
16+
identifiers: 'short',
17+
});

0 commit comments

Comments
 (0)