Skip to content

Commit

Permalink
Fix tsup configuration for vanilla Webpack 4 without babel-loader (#…
Browse files Browse the repository at this point in the history
…5322)

* Update barrel files

* Emit CJS as ES2019

* Force code splitting in CJS

* Add entry
  • Loading branch information
compulim authored Oct 9, 2024
1 parent 4880020 commit 63e5cb0
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
- Fixed typings of `useFocus` and `useLocalizer`
- 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)
- 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)
- 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)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion packages/api/decorator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This is required for Webpack 4 which does not support named exports.
// eslint-disable-next-line no-undef
module.exports = require('./dist/botframework-webchat-api.decorator');
module.exports = require('./dist/botframework-webchat-api.decorator.js');
2 changes: 1 addition & 1 deletion packages/api/internal.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This is required for Webpack 4 which does not support named exports.
// eslint-disable-next-line no-undef
module.exports = require('./dist/botframework-webchat-api.internal');
module.exports = require('./dist/botframework-webchat-api.internal.js');
19 changes: 15 additions & 4 deletions packages/api/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import { defineConfig } from 'tsup';
import baseConfig from '../../tsup.base.config';

export default defineConfig({
const config: typeof baseConfig = {
...baseConfig,
entry: {
'botframework-webchat-api': './src/index.ts',
'botframework-webchat-api.internal': './src/internal.ts',
'botframework-webchat-api.decorator': './src/decorator/index.ts'
}
};

export default defineConfig([
{
...config,
format: 'esm',
noExternal: ['globalize']
},
noExternal: ['globalize'],
format: ['esm', 'cjs']
});
{
...config,
format: 'cjs',
target: [...config.target, 'es2019']
}
]);
17 changes: 14 additions & 3 deletions packages/base/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { defineConfig } from 'tsup';
import baseConfig from '../../tsup.base.config';

export default defineConfig({
const config: typeof baseConfig = {
...baseConfig,
entry: {
'botframework-webchat-base': './src/index.ts',
'botframework-webchat-base.utils': './src/utils/index.ts'
}
};

export default defineConfig([
{
...config,
format: 'esm'
},
format: ['esm', 'cjs']
});
{
...config,
format: 'cjs',
target: [...config.target, 'es2019']
}
]);
2 changes: 1 addition & 1 deletion packages/base/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This is required for Webpack 4 which does not support named exports.
// eslint-disable-next-line no-undef
module.exports = require('./dist/botframework-webchat-base.utils');
module.exports = require('./dist/botframework-webchat-base.utils.js');
19 changes: 15 additions & 4 deletions packages/bundle/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const resolveCognitiveServicesToES2015 = {
}
};

export default defineConfig({
const config: typeof baseConfig = {
...baseConfig,
entry: {
'botframework-webchat': './src/index.ts',
Expand All @@ -34,6 +34,17 @@ export default defineConfig({
'memoize-one',
'microsoft-cognitiveservices-speech-sdk',
'web-speech-cognitive-services'
],
format: ['esm', 'cjs']
});
]
};

export default defineConfig([
{
...config,
format: 'esm'
},
{
...config,
format: 'cjs',
target: [...config.target, 'es2019']
}
]);
2 changes: 1 addition & 1 deletion packages/component/decorator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This is required for Webpack 4 which does not support named exports.
// eslint-disable-next-line no-undef
module.exports = require('./lib/decorator/index');
module.exports = require('./dist/botframework-webchat-component.decorator.js');
2 changes: 1 addition & 1 deletion packages/component/internal.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This is required for Webpack 4 which does not support named exports.
// eslint-disable-next-line no-undef
module.exports = require('./lib/internal');
module.exports = require('./dist/botframework-webchat-component.internal.js');
19 changes: 15 additions & 4 deletions packages/component/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { injectCSSPlugin } from 'botframework-webchat-styles/build';
import { defineConfig } from 'tsup';
import baseConfig from '../../tsup.base.config';
import { componentStyleContent as componentStyleContentPlaceholder } from './src/Styles/createStyles';
import { decoratorStyleContent as decoratorStyleContentPlaceholder } from './src/decorator/private/createStyles';
import { injectCSSPlugin } from 'botframework-webchat-styles/build';

export default defineConfig({
const config: typeof baseConfig = {
...baseConfig,
loader: {
...baseConfig.loader,
Expand All @@ -18,6 +18,17 @@ export default defineConfig({
'botframework-webchat-component': './src/index.ts',
'botframework-webchat-component.internal': './src/internal.ts',
'botframework-webchat-component.decorator': './src/decorator/index.ts'
}
};

export default defineConfig([
{
...config,
format: 'esm'
},
format: ['esm', 'cjs']
});
{
...config,
format: 'cjs',
target: [...config.target, 'es2019']
}
]);
17 changes: 14 additions & 3 deletions packages/core/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { defineConfig } from 'tsup';
import baseConfig from '../../tsup.base.config';

export default defineConfig({
const config: typeof baseConfig = {
...baseConfig,
entry: {
'botframework-webchat-core': './src/index.ts'
}
};

export default defineConfig([
{
...config,
format: 'esm'
},
format: ['esm', 'cjs']
});
{
...config,
format: 'cjs',
target: [...config.target, 'es2019']
}
]);
16 changes: 14 additions & 2 deletions packages/directlinespeech/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const resolveCognitiveServicesToES2015 = {
}
};

export default defineConfig({
const config: typeof baseConfig = {
...baseConfig,
entry: {
'botframework-directlinespeech-sdk': './src/index.js'
Expand All @@ -29,4 +29,16 @@ export default defineConfig({
esbuildPlugins: [resolveCognitiveServicesToES2015],
// We need to internalize event-target-shim because it appear as transient packages with a different version.
noExternal: ['event-target-shim']
});
};

export default defineConfig([
{
...config,
format: 'esm'
},
{
...config,
format: 'cjs',
target: [...config.target, 'es2019']
}
]);
3 changes: 2 additions & 1 deletion packages/fluent-theme/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export default defineConfig([
'.css': 'local-css'
},
esbuildPlugins: [...(baseConfig.esbuildPlugins || []), injectCSSPlugin({ stylesPlaceholder: fluentStyleContentPlaceholder })],
format: ['cjs']
format: ['cjs'],
target: [...baseConfig.target, 'es2019']
},
{
...baseConfig,
Expand Down
17 changes: 14 additions & 3 deletions packages/styles/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import { defineConfig } from 'tsup';
import baseConfig from '../../tsup.base.config';

export default defineConfig({
const config: typeof baseConfig = {
...baseConfig,
entry: {
'botframework-webchat-styles': './src/index.ts',
'botframework-webchat-styles.build': './src/build/index.ts',
'botframework-webchat-styles.react': './src/react/index.ts'
}
};

export default defineConfig([
{
...config,
format: 'esm'
},
format: ['esm', 'cjs']
});
{
...config,
format: 'cjs',
target: [...config.target, 'es2019']
}
]);
13 changes: 9 additions & 4 deletions tsup.base.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { defineConfig, type Options } from 'tsup';
import { type Options } from 'tsup';
import { babelPlugin, defaultPredicate, type Predicate } from './esbuildBabelPluginIstanbul';

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

const env = process.env.NODE_ENV || 'development';
const { npm_package_version } = process.env;
const istanbulPredicate: Predicate = args => defaultPredicate(args) && !/\.worker\.[cm]?[jt]s$/u.test(args.path);

export default defineConfig({
const baseConfig: Options & { target: Target[] } = {
dts: true,
env: {
build_tool: 'tsup',
Expand Down Expand Up @@ -52,5 +54,8 @@ export default defineConfig({
minify: env === 'production',
platform: 'browser',
sourcemap: true,
target: ['chrome100', 'firefox100', 'safari15']
}) as Options;
splitting: true,
target: ['chrome100', 'firefox100', 'safari15'] satisfies Target[]
};

export default baseConfig;

0 comments on commit 63e5cb0

Please sign in to comment.