Skip to content

Commit 6644012

Browse files
committed
page size handling
1 parent 00f649a commit 6644012

23 files changed

+1867
-323
lines changed

build/esbuild/build.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { lessLoader } from 'esbuild-plugin-less';
99
import fs from 'fs-extra';
1010
import { getZeroMQPreBuildsFoldersToKeep, getBundleConfiguration, bundleConfiguration } from '../webpack/common';
1111
import ImportGlobPlugin from 'esbuild-plugin-import-glob';
12+
import postcss from 'postcss';
13+
import tailwindcss from '@tailwindcss/postcss';
14+
import autoprefixer from 'autoprefixer';
1215
const plugin = require('node-stdlib-browser/helpers/esbuild/plugin');
1316
const stdLibBrowser = require('node-stdlib-browser');
1417

@@ -86,7 +89,11 @@ const loader: { [ext: string]: Loader } = {
8689

8790
// https://github.com/evanw/esbuild/issues/20#issuecomment-802269745
8891
// https://github.com/hyrious/esbuild-plugin-style
89-
function style({ minify = true, charset = 'utf8' }: StylePluginOptions = {}): Plugin {
92+
function style({
93+
minify = true,
94+
charset = 'utf8',
95+
enableTailwind = false
96+
}: StylePluginOptions & { enableTailwind?: boolean } = {}): Plugin {
9097
return {
9198
name: 'style',
9299
setup({ onResolve, onLoad }) {
@@ -132,6 +139,27 @@ function style({ minify = true, charset = 'utf8' }: StylePluginOptions = {}): Pl
132139
}));
133140

134141
onLoad({ filter: /.*/, namespace: 'style-content' }, async (args) => {
142+
// Process with PostCSS/Tailwind if enabled and file exists
143+
if (enableTailwind && args.path.includes('tailwind.css') && fs.existsSync(args.path)) {
144+
const cssContent = await fs.readFile(args.path, 'utf8');
145+
const result = await postcss([tailwindcss, autoprefixer]).process(cssContent, {
146+
from: args.path,
147+
to: args.path
148+
});
149+
150+
const options = { ...opt, stdin: { contents: result.css, loader: 'css' } };
151+
options.loader = options.loader || {};
152+
// Add the same loaders we add for other places
153+
Object.keys(loader).forEach((key) => {
154+
if (options.loader && !options.loader[key]) {
155+
options.loader[key] = loader[key];
156+
}
157+
});
158+
const { errors, warnings, outputFiles } = await esbuild.build(options);
159+
return { errors, warnings, contents: outputFiles![0].text, loader: 'text' };
160+
}
161+
162+
// Default behavior for other CSS files
135163
const options = { entryPoints: [args.path], ...opt };
136164
options.loader = options.loader || {};
137165
// Add the same loaders we add for other places
@@ -158,7 +186,9 @@ function createConfig(
158186
const plugins: Plugin[] = [];
159187
let define: SameShape<BuildOptions, BuildOptions>['define'] = undefined;
160188
if (target === 'web') {
161-
plugins.push(style());
189+
// Enable Tailwind processing for dataframe renderer
190+
const enableTailwind = source.includes(path.join('dataframe-renderer', 'index.ts'));
191+
plugins.push(style({ enableTailwind }));
162192
plugins.push(lessLoader());
163193

164194
define = {

0 commit comments

Comments
 (0)