Skip to content

Commit 7f634f8

Browse files
authored
fix: unminify css when bundling (#2710)
* fix: unminify css when bundling * docs: import maps for all elements * fix: unwrap nesting in bundle
1 parent 4fceffb commit 7f634f8

File tree

6 files changed

+77
-16
lines changed

6 files changed

+77
-16
lines changed

docs/_data/importMap.cjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,22 @@ module.exports = async function() {
100100
for (const file of pfeCoreImports) {
101101
map.imports[path.join('@patternfly/pfe-core', file)] = '/pfe.min.js';
102102
}
103+
103104
map.imports['@patternfly/pfe-core/decorators.js'] = '/pfe.min.js';
104105
map.imports['@patternfly/pfe-core'] = '/pfe.min.js';
105106

106-
for (const tagName of fs.readdirSync(path.join(__dirname, '..', '..', 'elements'))) {
107-
map.imports[`@patternfly/elements/${tagName}/${tagName}.js`] = `/pfe.min.js`;
107+
const elementsPath = path.join(__dirname, '..', '..', 'elements');
108+
for (const tagName of fs.readdirSync(elementsPath)) {
109+
const elementPath = path.join(elementsPath, tagName);
110+
if (fs.statSync(elementPath).isDirectory()) {
111+
for (const fileName of fs.readdirSync(elementPath)) {
112+
if (fileName.endsWith('.ts') && !fileName.endsWith('.d.ts')) {
113+
map.imports[`@patternfly/elements/${tagName}/${fileName.replace('.ts', '')}.js`] = `/pfe.min.js`;
114+
}
115+
}
116+
}
108117
}
118+
109119
map.imports['@patternfly/pfe-tools/environment.js'] = '/tools/environment.js';
110120

111121

package-lock.json

Lines changed: 53 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@
314314
"leasot": "^13.3.0",
315315
"lit": "^3.1.2",
316316
"nunjucks": "^3.2.4",
317+
"postcss-nesting": "^12.1.0",
317318
"prompts": "^2.4.2",
318319
"wireit": "^0.14.4",
319320
"zero-md": "^2.5.3"

scripts/bundle.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@ import { join } from 'node:path';
55
import { fileURLToPath } from 'node:url';
66
import { litCssPlugin } from 'esbuild-plugin-lit-css';
77
import { glob } from 'glob';
8-
import CleanCSS from 'clean-css';
8+
9+
import postcss from 'postcss';
10+
import postcssNesting from 'postcss-nesting';
911

1012
const resolveDir = join(fileURLToPath(import.meta.url), '../../elements');
1113
const entryPoints = (await glob('./pf-*/pf-*.ts', { cwd: resolveDir })).map(x => x.replace('.ts', '.js'));
1214
const contents = entryPoints.map(x => `export * from './${x}';`).join('\n');
1315

14-
const cleanCSS = new CleanCSS({
15-
sourceMap: true,
16-
returnPromise: true,
17-
});
18-
1916
export async function bundle({ outfile = 'elements/pfe.min.js' } = {}) {
2017
await build({
2118
stdin: {
@@ -42,8 +39,13 @@ export async function bundle({ outfile = 'elements/pfe.min.js' } = {}) {
4239

4340
plugins: [
4441
litCssPlugin({
42+
cssnano: false,
43+
uglify: false,
4544
filter: /\.css$/,
46-
transform: source => cleanCSS.minify(source).then(x => x.styles)
45+
transform: (str, { filePath }) =>
46+
postcss(postcssNesting())
47+
.process(str, { from: filePath })
48+
.css
4749
}),
4850
],
4951
});

tsconfig.esbuild.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
"plugins": [
4545
{
4646
"transform": "@patternfly/pfe-tools/typescript/transformers/css-imports.cjs",
47-
"inline": true,
48-
"minify": true
47+
"inline": true
4948
},
5049
{
5150
"name": "typescript-lit-html-plugin"

tsconfig.settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
"plugins": [
3939
{
4040
"transform": "@patternfly/pfe-tools/typescript/transformers/css-imports.cjs",
41-
"inline": true,
42-
"minify": true
41+
"inline": true
4342
},
4443
{
4544
"name": "typescript-lit-html-plugin"

0 commit comments

Comments
 (0)