Skip to content

Commit 2654667

Browse files
authored
ESM static build should target Chrome 100 with Lightning CSS (#5602)
* Fix Fluent CSS * Update PR number
1 parent b27f9b7 commit 2654667

File tree

8 files changed

+40
-29
lines changed

8 files changed

+40
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
142142
- Bundling vendor chunks, by [@compulim](https://github.com/compulim) in PR [#5595](https://github.com/microsoft/BotFramework-WebChat/pull/5595)
143143
- Added deprecation notes for legacy imports, by [@compulim](https://github.com/compulim) in PR [#5600](https://github.com/microsoft/BotFramework-WebChat/pull/5600)
144144
- `import { hooks } from 'botframework-webchat'` should be replaced by `import * as hooks from 'botframework-webchat/hook'`
145+
- Added target to Chrome 100 and re-enable Lightning CSS for ESM builds, by [@compulim](https://github.com/compulim) in PR [#5602](https://github.com/microsoft/BotFramework-WebChat/pull/5602)
145146
- Relaxed `role` prop to allow any string instead of ARIA landmark roles, in PR [#5561](https://github.com/microsoft/BotFramework-WebChat/pull/5561), by [@compulim](https://github.com/compulim)
146147

147148
### Changed
525 Bytes
Loading
525 Bytes
Loading
525 Bytes
Loading

esbuildPlugins.mjs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import lightningCssPlugin from 'unplugin-lightningcss/esbuild';
2+
3+
// Due to a bug in unplugin, we cannot use the Lightning CSS unplugin directly.
4+
// https://github.com/unjs/unplugin/issues/546
5+
// To workaround the bug, we are converting it back to esbuild plugin so we can apply a custom `filter`.
6+
// Otherwise, unplugin will apply `filter: /.*/` and trigger the bug down the road.
7+
8+
/** @type { import('esbuild').Plugin } */
9+
const cssPlugin = {
10+
name: 'lightningcss',
11+
setup: build => {
12+
lightningCssPlugin({
13+
include: [/\.module\.css$/u],
14+
options: {
15+
cssModules: {
16+
pattern: 'w[hash]_[local]',
17+
pure: true,
18+
animation: false,
19+
grid: false,
20+
customIdents: false
21+
}
22+
}
23+
}).setup({
24+
...build,
25+
// eslint-disable-next-line require-unicode-regexp
26+
onLoad: (_filter, fn) => build.onLoad({ filter: /(\.module_built\.css|\?css_module)$/ }, fn)
27+
});
28+
}
29+
};
30+
31+
export { cssPlugin };

packages/bundle/esbuild.static.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { build, context } from 'esbuild';
99
import { resolve } from 'path';
1010
import { readPackage } from 'read-pkg';
1111
import { fileURLToPath } from 'url';
12+
import { cssPlugin } from '../../esbuildPlugins.mjs';
1213

1314
// eslint-disable-next-line no-unused-vars
1415
const isomorphicReactPlugin = {
@@ -73,8 +74,10 @@ const BASE_CONFIG = {
7374
minify: true,
7475
outdir: resolve(fileURLToPath(import.meta.url), `../static/`),
7576
platform: 'browser',
77+
plugins: [cssPlugin],
7678
sourcemap: true,
77-
splitting: true
79+
splitting: true,
80+
target: ['chrome100', 'firefox100', 'safari15']
7881
};
7982

8083
function* getKeysRecursive(exports) {

packages/fluent-theme/esbuild.static.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { build, context } from 'esbuild';
1010
import { mkdir, writeFile } from 'fs/promises';
1111
import { dirname, resolve } from 'path';
1212
import { fileURLToPath } from 'url';
13+
import { cssPlugin } from '../../esbuildPlugins.mjs';
1314

1415
// TODO: [P0] We cannot import TypeScript file here.
1516
const fluentStyleContentPlaceholder = '@--FLUENT-STYLES-CONTENT--@';
@@ -53,6 +54,7 @@ const config = {
5354
outdir: resolve(fileURLToPath(import.meta.url), `../static/`),
5455
platform: 'browser',
5556
plugins: [
57+
cssPlugin,
5658
injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder }),
5759
{
5860
// `write` is set to `false`, we need to emit files ourselves.
@@ -74,6 +76,7 @@ const config = {
7476
],
7577
sourcemap: true,
7678
splitting: true,
79+
target: ['chrome100', 'firefox100', 'safari15'],
7780
// Set write to false for the `injectCSSPlugin` to work.
7881
// We will emit the output in another plugin.
7982
write: false

tsup.base.config.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { type Plugin } from 'esbuild';
21
import { type Options } from 'tsup';
3-
import lightningCssPlugin from 'unplugin-lightningcss/esbuild';
42

53
import { babelPlugin, defaultPredicate, type Predicate } from './esbuildBabelPluginIstanbul';
4+
import { cssPlugin } from './esbuildPlugins.mjs';
65

76
type Target = Exclude<Options['target'], Array<unknown> | undefined>;
87

@@ -21,32 +20,6 @@ const disablePlugin = (pluginName: string): EsbuildPlugin => ({
2120
}
2221
});
2322

24-
// Due to a bug in unplugin, we cannot use the Lightning CSS unplugin directly.
25-
// https://github.com/unjs/unplugin/issues/546
26-
// To workaround the bug, we are converting it back to esbuild plugin so we can apply a custom `filter`.
27-
// Otherwise, unplugin will apply `filter: /.*/` and trigger the bug down the road.
28-
const cssPlugin: Plugin = {
29-
name: 'lightningcss',
30-
setup: build => {
31-
lightningCssPlugin({
32-
include: [/\.module\.css$/u],
33-
options: {
34-
cssModules: {
35-
pattern: 'w[hash]_[local]',
36-
pure: true,
37-
animation: false,
38-
grid: false,
39-
customIdents: false
40-
}
41-
}
42-
}).setup({
43-
...build,
44-
// eslint-disable-next-line require-unicode-regexp
45-
onLoad: (_filter, fn) => build.onLoad({ filter: /(\.module_built\.css|\?css_module)$/ }, fn)
46-
});
47-
}
48-
};
49-
5023
function applyConfig(
5124
overrideOptions: (
5225
options: Omit<Options, 'entry' | 'onSuccess'> & {

0 commit comments

Comments
 (0)