Skip to content

Commit 182e3a0

Browse files
authored
chore: remove CSS imports when running yarn start:base (#9273)
1 parent 2aa9b75 commit 182e3a0

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

web-dev-server.config.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,35 @@ export function cssImportPlugin() {
3737
}
3838

3939
/** @return {import('@web/test-runner').TestRunnerPlugin} */
40-
export function enforceLegacyLumoPlugin() {
40+
export function enforceThemePlugin(theme) {
4141
return {
42-
name: 'enforce-legacy-lumo',
42+
name: 'enforce-theme',
4343
transform(context) {
44-
if (context.response.is('js', 'html')) {
45-
return context.body
46-
.replaceAll(
47-
`import '@vaadin/vaadin-lumo-styles/global.css'`,
48-
`import '@vaadin/vaadin-lumo-styles/test/autoload.js'`,
49-
)
50-
.replaceAll(/^.*@vaadin\/vaadin-lumo-styles\/.*\.css.*$/gmu, '');
44+
let { body } = context;
45+
46+
if (context.response.is('html') && (theme === 'base' || theme === 'ported-lumo')) {
47+
// Load the base theme
48+
body = body.replace('./common.js', './common-base.js');
5149
}
52-
},
53-
};
54-
}
5550

56-
/** @return {import('@web/test-runner').TestRunnerPlugin} */
57-
export function enforceBaseStylesPlugin() {
58-
return {
59-
name: 'enforce-base-styles',
60-
transform(context) {
61-
if (context.response.is('html')) {
62-
return { body: context.body.replace('./common.js', './common-base.js') };
51+
if (context.response.is('html', 'js') && (theme === 'base' || theme === 'legacy-lumo')) {
52+
// Remove all CSS imports
53+
body = body.replaceAll(/^.+vaadin-lumo-styles\/.+\.css.+$/gmu, '');
6354
}
55+
56+
return body;
6457
},
6558
transformImport({ source }) {
66-
source = source.replace('/theme/lumo/', '/src/');
67-
source = source.replace(/(.+)-core-styles\.js/u, '$1-base-styles.js');
59+
if (theme === 'base' || theme === 'ported-lumo') {
60+
// Load the base theme
61+
source = source.replace('/theme/lumo/', '/src/');
62+
source = source.replace(/(.+)-core-styles\.js/u, '$1-base-styles.js');
63+
}
64+
65+
if (theme === 'legacy-lumo') {
66+
source = source.replace('vaadin-lumo-styles/global.css', 'vaadin-lumo-styles/test/autoload.js');
67+
}
68+
6869
return source;
6970
},
7071
};
@@ -120,13 +121,13 @@ export default {
120121
esbuildPlugin({ ts: true }),
121122

122123
// yarn start --theme=base
123-
theme === 'base' && enforceBaseStylesPlugin(),
124+
theme === 'base' && enforceThemePlugin('base'),
124125

125126
// yarn start --theme=lumo (uses legacy lumo styles defined in js files)
126-
theme === 'lumo' && !hasPortedParam && enforceLegacyLumoPlugin(),
127+
theme === 'lumo' && !hasPortedParam && enforceThemePlugin('legacy-lumo'),
127128

128129
// yarn start --theme=lumo --ported (uses base styles and lumo styles defined in css files)
129-
theme === 'lumo' && hasPortedParam && enforceBaseStylesPlugin(),
130+
theme === 'lumo' && hasPortedParam && enforceThemePlugin('ported-lumo'),
130131
theme === 'lumo' && hasPortedParam && cssImportPlugin(),
131132
].filter(Boolean),
132133
};

wtr-utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import minimist from 'minimist';
99
import { execSync } from 'node:child_process';
1010
import fs from 'node:fs';
1111
import path from 'node:path';
12-
import { cssImportPlugin, enforceBaseStylesPlugin, enforceLegacyLumoPlugin } from './web-dev-server.config.js';
12+
import { cssImportPlugin, enforceThemePlugin } from './web-dev-server.config.js';
1313

1414
dotenv.config();
1515

@@ -349,13 +349,13 @@ const createVisualTestsConfig = (theme, browserVersion) => {
349349
}),
350350

351351
// yarn test:base
352-
theme === 'base' && enforceBaseStylesPlugin(),
352+
theme === 'base' && enforceThemePlugin('base'),
353353

354354
// yarn test:lumo (uses legacy lumo styles defined in js files)
355-
theme === 'lumo' && !hasPortedParam && enforceLegacyLumoPlugin(),
355+
theme === 'lumo' && !hasPortedParam && enforceThemePlugin('legacy-lumo'),
356356

357357
// yarn test:lumo --ported (uses base styles and lumo styles defined in css files)
358-
theme === 'lumo' && hasPortedParam && enforceBaseStylesPlugin(),
358+
theme === 'lumo' && hasPortedParam && enforceThemePlugin('ported-lumo'),
359359
theme === 'lumo' && hasPortedParam && cssImportPlugin(),
360360
].filter(Boolean),
361361
groups,

0 commit comments

Comments
 (0)