Skip to content

Commit cb7c4a9

Browse files
committed
Polish fluent build
1 parent bce8f8b commit cb7c4a9

2 files changed

Lines changed: 69 additions & 51 deletions

File tree

packages/bundle/tsdown.config.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { defineConfig } from 'tsdown';
33
import baseConfig from '../../tsdown.base.config';
44
import type { Plugin as RollupPlugin } from 'rollup';
55

6-
import pkg from './package.json'
6+
import pkg from './package.json';
77

88
const iifeDeps = Object.keys(pkg.dependencies);
99

@@ -79,14 +79,11 @@ const iifeConfig = {
7979
format: 'iife',
8080
platform: 'browser',
8181
target: [...config.target, 'es2019'],
82-
noExternal: [
83-
...iifeDeps,
84-
...config.noExternal,
85-
],
82+
noExternal: [...iifeDeps, ...config.noExternal],
8683
outputOptions(outputOptions) {
8784
outputOptions.entryFileNames = '[name].js';
8885
return outputOptions;
89-
},
86+
}
9087
};
9188

9289
export default defineConfig([
@@ -100,7 +97,7 @@ export default defineConfig([
10097
{
10198
...iifeConfig,
10299
entry: {
103-
'webchat': './src/bundle/index.ts'
100+
webchat: './src/bundle/index.ts'
104101
}
105102
},
106103
{
@@ -112,7 +109,7 @@ export default defineConfig([
112109
{
113110
...config,
114111
format: 'esm'
115-
},
112+
}
116113
// {
117114
// ...config,
118115
// format: 'cjs',

packages/fluent-theme/tsdown.config.ts

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,38 @@ import baseConfig from '../../tsdown.base.config';
55
import { fluentStyleContent as fluentStyleContentPlaceholder } from './src/styles/createStyles';
66
import { injectCSSPlugin } from 'botframework-webchat-styles/build';
77
import LightningCSS from 'unplugin-lightningcss';
8+
import type { Plugin } from 'rollup';
89

9-
const umdResolvePlugin = {
10-
name: 'umd-resolve',
11-
setup(build) {
12-
build.onResolve({ filter: /^react$/u }, () => ({
13-
path: join(fileURLToPath(import.meta.url), '../src/external.umd/react.ts')
14-
}));
15-
16-
build.onResolve({ filter: /^botframework-webchat-api$/u }, () => ({
17-
path: join(fileURLToPath(import.meta.url), '../src/external.umd/botframework-webchat-api/index.ts')
18-
}));
19-
20-
build.onResolve({ filter: /^botframework-webchat-api\/decorator$/u }, () => ({
21-
path: join(fileURLToPath(import.meta.url), '../src/external.umd/botframework-webchat-api/decorator.ts')
22-
}));
23-
24-
build.onResolve({ filter: /^botframework-webchat-component$/u }, () => ({
25-
path: join(fileURLToPath(import.meta.url), '../src/external.umd/botframework-webchat-component/index.ts')
26-
}));
10+
import pkg from './package.json';
2711

28-
build.onResolve({ filter: /^botframework-webchat-component\/internal$/u }, () => ({
29-
path: join(fileURLToPath(import.meta.url), '../src/external.umd/botframework-webchat-component/internal.ts')
30-
}));
12+
const iifeDeps = [
13+
'botframework-webchat-component/decorator',
14+
'botframework-webchat-api/decorator',
15+
'botframework-webchat-component/internal'
16+
].concat(Object.keys(pkg.dependencies));
3117

32-
build.onResolve({ filter: /^botframework-webchat-component\/decorator$/u }, () => ({
33-
path: join(fileURLToPath(import.meta.url), '../src/external.umd/botframework-webchat-component/decorator.ts')
34-
}));
18+
const umdResolvePlugin: Plugin = {
19+
name: 'umd-resolve',
20+
resolveId(source) {
21+
if (source === 'react') {
22+
return join(fileURLToPath(import.meta.url), '../src/external.umd/react.ts');
23+
}
24+
if (source === 'botframework-webchat-api') {
25+
return join(fileURLToPath(import.meta.url), '../src/external.umd/botframework-webchat-api/index.ts');
26+
}
27+
if (source === 'botframework-webchat-api/decorator') {
28+
return join(fileURLToPath(import.meta.url), '../src/external.umd/botframework-webchat-api/decorator.ts');
29+
}
30+
if (source === 'botframework-webchat-component') {
31+
return join(fileURLToPath(import.meta.url), '../src/external.umd/botframework-webchat-component/index.ts');
32+
}
33+
if (source === 'botframework-webchat-component/internal') {
34+
return join(fileURLToPath(import.meta.url), '../src/external.umd/botframework-webchat-component/internal.ts');
35+
}
36+
if (source === 'botframework-webchat-component/decorator') {
37+
return join(fileURLToPath(import.meta.url), '../src/external.umd/botframework-webchat-component/decorator.ts');
38+
}
39+
return null;
3540
}
3641
};
3742

@@ -40,45 +45,61 @@ export default defineConfig([
4045
...baseConfig,
4146
entry: { 'botframework-webchat-fluent-theme': './src/index.ts' },
4247
env: { ...baseConfig.env, module_format: 'commonjs' },
43-
plugins: [
44-
LightningCSS.rolldown()
48+
plugins: [LightningCSS.rolldown()],
49+
esbuildPlugins: [
50+
...(baseConfig.esbuildPlugins || []),
51+
injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder })
4552
],
46-
esbuildPlugins: [...(baseConfig.esbuildPlugins || []), injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder })],
4753
format: ['cjs'],
48-
target: [...baseConfig.target, 'es2019']
54+
target: [...baseConfig.target, 'es2019'],
4955
},
5056
{
5157
...baseConfig,
5258
entry: { 'botframework-webchat-fluent-theme': './src/index.ts' },
53-
plugins: [
54-
LightningCSS.rolldown()
59+
plugins: [LightningCSS.rolldown()],
60+
esbuildPlugins: [
61+
...(baseConfig.esbuildPlugins || []),
62+
injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder })
5563
],
56-
esbuildPlugins: [...(baseConfig.esbuildPlugins || []), injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder })],
5764
format: ['esm']
5865
},
5966
{
6067
...baseConfig,
6168
entry: { 'botframework-webchat-fluent-theme.development': './src/bundle.ts' },
62-
esbuildPlugins: [...(baseConfig.esbuildPlugins || []), injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder }), umdResolvePlugin],
63-
plugins: [
64-
LightningCSS.rolldown()
69+
esbuildPlugins: [
70+
...(baseConfig.esbuildPlugins || []),
71+
injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder })
6572
],
73+
plugins: [LightningCSS.rolldown(), umdResolvePlugin],
6674
format: 'iife',
67-
outExtension() {
68-
return { js: '.js' };
69-
}
75+
outputOptions(outputOptions) {
76+
outputOptions.entryFileNames = '[name].js';
77+
outputOptions.globals = {
78+
react: 'React',
79+
'react/jsx-runtime': 'React'
80+
};
81+
return outputOptions;
82+
},
83+
noExternal: iifeDeps
7084
},
7185
{
7286
...baseConfig,
7387
entry: { 'botframework-webchat-fluent-theme.production.min': './src/bundle.ts' },
74-
esbuildPlugins: [...(baseConfig.esbuildPlugins || []), injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder }), umdResolvePlugin],
75-
plugins: [
76-
LightningCSS.rolldown()
88+
esbuildPlugins: [
89+
...(baseConfig.esbuildPlugins || []),
90+
injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder })
7791
],
92+
plugins: [LightningCSS.rolldown(), umdResolvePlugin],
7893
format: 'iife',
7994
minify: true,
80-
outExtension() {
81-
return { js: '.js' };
82-
}
95+
outputOptions(outputOptions) {
96+
outputOptions.entryFileNames = '[name].js';
97+
outputOptions.globals = {
98+
react: 'React',
99+
'react/jsx-runtime': 'React'
100+
};
101+
return outputOptions;
102+
},
103+
noExternal: iifeDeps
83104
}
84105
]);

0 commit comments

Comments
 (0)