Skip to content

Commit 63e5cb0

Browse files
authored
Fix tsup configuration for vanilla Webpack 4 without babel-loader (#5322)
* Update barrel files * Emit CJS as ES2019 * Force code splitting in CJS * Add entry
1 parent 4880020 commit 63e5cb0

15 files changed

+118
-33
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
808808
- Fixed typings of `useFocus` and `useLocalizer`
809809
- Fixes [#3165](https://github.com/microsoft/BotFramework-WebChat/issues/3165) and [#4094](https://github.com/microsoft/BotFramework-WebChat/issues/4094). Allowlist `aria-label` for links in Markdown and skip unrecognized attributes or invalid curly brackets, by [@compulim](https://github.com/compulim), in PR [#4095](https://github.com/microsoft/BotFramework-WebChat/pull/4095)
810810
- Fixes [#4190](https://github.com/microsoft/BotFramework-WebChat/issues/4190). Recent Markdown curly bracket fix should not break IE11 due to unsupported "u" flag in `RegExp`, by [@compulim](https://github.com/compulim), in PR [#4191](https://github.com/microsoft/BotFramework-WebChat/pull/4191)
811+
- Improved importability in vanilla Webpack 4 without `babel-loader`, by [@compulim](https://github.com/compulim), in PR [#5322](https://github.com/microsoft/BotFramework-WebChat/pull/5322)
811812

812813
### Changed
813814

packages/api/decorator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This is required for Webpack 4 which does not support named exports.
22
// eslint-disable-next-line no-undef
3-
module.exports = require('./dist/botframework-webchat-api.decorator');
3+
module.exports = require('./dist/botframework-webchat-api.decorator.js');

packages/api/internal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This is required for Webpack 4 which does not support named exports.
22
// eslint-disable-next-line no-undef
3-
module.exports = require('./dist/botframework-webchat-api.internal');
3+
module.exports = require('./dist/botframework-webchat-api.internal.js');

packages/api/tsup.config.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import { defineConfig } from 'tsup';
22
import baseConfig from '../../tsup.base.config';
33

4-
export default defineConfig({
4+
const config: typeof baseConfig = {
55
...baseConfig,
66
entry: {
77
'botframework-webchat-api': './src/index.ts',
88
'botframework-webchat-api.internal': './src/internal.ts',
99
'botframework-webchat-api.decorator': './src/decorator/index.ts'
10+
}
11+
};
12+
13+
export default defineConfig([
14+
{
15+
...config,
16+
format: 'esm',
17+
noExternal: ['globalize']
1018
},
11-
noExternal: ['globalize'],
12-
format: ['esm', 'cjs']
13-
});
19+
{
20+
...config,
21+
format: 'cjs',
22+
target: [...config.target, 'es2019']
23+
}
24+
]);

packages/base/tsup.config.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import { defineConfig } from 'tsup';
22
import baseConfig from '../../tsup.base.config';
33

4-
export default defineConfig({
4+
const config: typeof baseConfig = {
55
...baseConfig,
66
entry: {
77
'botframework-webchat-base': './src/index.ts',
88
'botframework-webchat-base.utils': './src/utils/index.ts'
9+
}
10+
};
11+
12+
export default defineConfig([
13+
{
14+
...config,
15+
format: 'esm'
916
},
10-
format: ['esm', 'cjs']
11-
});
17+
{
18+
...config,
19+
format: 'cjs',
20+
target: [...config.target, 'es2019']
21+
}
22+
]);

packages/base/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This is required for Webpack 4 which does not support named exports.
22
// eslint-disable-next-line no-undef
3-
module.exports = require('./dist/botframework-webchat-base.utils');
3+
module.exports = require('./dist/botframework-webchat-base.utils.js');

packages/bundle/tsup.config.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const resolveCognitiveServicesToES2015 = {
1313
}
1414
};
1515

16-
export default defineConfig({
16+
const config: typeof baseConfig = {
1717
...baseConfig,
1818
entry: {
1919
'botframework-webchat': './src/index.ts',
@@ -34,6 +34,17 @@ export default defineConfig({
3434
'memoize-one',
3535
'microsoft-cognitiveservices-speech-sdk',
3636
'web-speech-cognitive-services'
37-
],
38-
format: ['esm', 'cjs']
39-
});
37+
]
38+
};
39+
40+
export default defineConfig([
41+
{
42+
...config,
43+
format: 'esm'
44+
},
45+
{
46+
...config,
47+
format: 'cjs',
48+
target: [...config.target, 'es2019']
49+
}
50+
]);

packages/component/decorator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This is required for Webpack 4 which does not support named exports.
22
// eslint-disable-next-line no-undef
3-
module.exports = require('./lib/decorator/index');
3+
module.exports = require('./dist/botframework-webchat-component.decorator.js');

packages/component/internal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This is required for Webpack 4 which does not support named exports.
22
// eslint-disable-next-line no-undef
3-
module.exports = require('./lib/internal');
3+
module.exports = require('./dist/botframework-webchat-component.internal.js');

packages/component/tsup.config.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { injectCSSPlugin } from 'botframework-webchat-styles/build';
12
import { defineConfig } from 'tsup';
23
import baseConfig from '../../tsup.base.config';
34
import { componentStyleContent as componentStyleContentPlaceholder } from './src/Styles/createStyles';
45
import { decoratorStyleContent as decoratorStyleContentPlaceholder } from './src/decorator/private/createStyles';
5-
import { injectCSSPlugin } from 'botframework-webchat-styles/build';
66

7-
export default defineConfig({
7+
const config: typeof baseConfig = {
88
...baseConfig,
99
loader: {
1010
...baseConfig.loader,
@@ -18,6 +18,17 @@ export default defineConfig({
1818
'botframework-webchat-component': './src/index.ts',
1919
'botframework-webchat-component.internal': './src/internal.ts',
2020
'botframework-webchat-component.decorator': './src/decorator/index.ts'
21+
}
22+
};
23+
24+
export default defineConfig([
25+
{
26+
...config,
27+
format: 'esm'
2128
},
22-
format: ['esm', 'cjs']
23-
});
29+
{
30+
...config,
31+
format: 'cjs',
32+
target: [...config.target, 'es2019']
33+
}
34+
]);

packages/core/tsup.config.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import { defineConfig } from 'tsup';
22
import baseConfig from '../../tsup.base.config';
33

4-
export default defineConfig({
4+
const config: typeof baseConfig = {
55
...baseConfig,
66
entry: {
77
'botframework-webchat-core': './src/index.ts'
8+
}
9+
};
10+
11+
export default defineConfig([
12+
{
13+
...config,
14+
format: 'esm'
815
},
9-
format: ['esm', 'cjs']
10-
});
16+
{
17+
...config,
18+
format: 'cjs',
19+
target: [...config.target, 'es2019']
20+
}
21+
]);

packages/directlinespeech/tsup.config.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const resolveCognitiveServicesToES2015 = {
1313
}
1414
};
1515

16-
export default defineConfig({
16+
const config: typeof baseConfig = {
1717
...baseConfig,
1818
entry: {
1919
'botframework-directlinespeech-sdk': './src/index.js'
@@ -29,4 +29,16 @@ export default defineConfig({
2929
esbuildPlugins: [resolveCognitiveServicesToES2015],
3030
// We need to internalize event-target-shim because it appear as transient packages with a different version.
3131
noExternal: ['event-target-shim']
32-
});
32+
};
33+
34+
export default defineConfig([
35+
{
36+
...config,
37+
format: 'esm'
38+
},
39+
{
40+
...config,
41+
format: 'cjs',
42+
target: [...config.target, 'es2019']
43+
}
44+
]);

packages/fluent-theme/tsup.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export default defineConfig([
4444
'.css': 'local-css'
4545
},
4646
esbuildPlugins: [...(baseConfig.esbuildPlugins || []), injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder })],
47-
format: ['cjs']
47+
format: ['cjs'],
48+
target: [...baseConfig.target, 'es2019']
4849
},
4950
{
5051
...baseConfig,

packages/styles/tsup.config.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
import { defineConfig } from 'tsup';
22
import baseConfig from '../../tsup.base.config';
33

4-
export default defineConfig({
4+
const config: typeof baseConfig = {
55
...baseConfig,
66
entry: {
77
'botframework-webchat-styles': './src/index.ts',
88
'botframework-webchat-styles.build': './src/build/index.ts',
99
'botframework-webchat-styles.react': './src/react/index.ts'
10+
}
11+
};
12+
13+
export default defineConfig([
14+
{
15+
...config,
16+
format: 'esm'
1017
},
11-
format: ['esm', 'cjs']
12-
});
18+
{
19+
...config,
20+
format: 'cjs',
21+
target: [...config.target, 'es2019']
22+
}
23+
]);

tsup.base.config.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { defineConfig, type Options } from 'tsup';
1+
import { type Options } from 'tsup';
22
import { babelPlugin, defaultPredicate, type Predicate } from './esbuildBabelPluginIstanbul';
33

4+
type Target = Exclude<Options['target'], Array<unknown> | undefined>;
5+
46
const env = process.env.NODE_ENV || 'development';
57
const { npm_package_version } = process.env;
68
const istanbulPredicate: Predicate = args => defaultPredicate(args) && !/\.worker\.[cm]?[jt]s$/u.test(args.path);
79

8-
export default defineConfig({
10+
const baseConfig: Options & { target: Target[] } = {
911
dts: true,
1012
env: {
1113
build_tool: 'tsup',
@@ -52,5 +54,8 @@ export default defineConfig({
5254
minify: env === 'production',
5355
platform: 'browser',
5456
sourcemap: true,
55-
target: ['chrome100', 'firefox100', 'safari15']
56-
}) as Options;
57+
splitting: true,
58+
target: ['chrome100', 'firefox100', 'safari15'] satisfies Target[]
59+
};
60+
61+
export default baseConfig;

0 commit comments

Comments
 (0)