1+ /* eslint-disable require-unicode-regexp */
12import path from 'path' ;
23import { defineConfig } from 'tsup' ;
34import baseConfig from '../../tsup.base.config' ;
@@ -50,6 +51,26 @@ const config: typeof baseConfig = {
5051 ]
5152} ;
5253
54+ const externalCjsToEsmPlugin = external => ( {
55+ name : 'external' ,
56+ setup ( build ) {
57+ const escape = text => `^${ text . replace ( / [ - / \\ ^ $ * + ? . ( ) | [ \] { } ] / g, '\\$&' ) } $` ;
58+ // eslint-disable-next-line security/detect-non-literal-regexp
59+ const filter = new RegExp ( external . map ( escape ) . join ( '|' ) ) ;
60+ build . onResolve ( { filter : / .* / , namespace : 'external' } , args => ( {
61+ path : args . path ,
62+ external : true
63+ } ) ) ;
64+ build . onResolve ( { filter } , args => ( {
65+ path : args . path ,
66+ namespace : 'external'
67+ } ) ) ;
68+ build . onLoad ( { filter : / .* / , namespace : 'external' } , args => ( {
69+ contents : `export * from ${ JSON . stringify ( args . path ) } \nimport * as pkg from ${ JSON . stringify ( args . path ) } \nexport default pkg\n`
70+ } ) ) ;
71+ }
72+ } ) ;
73+
5374export default defineConfig ( [
5475 // Build IIFE before CJS/ESM to make npm start faster.
5576 {
@@ -72,6 +93,45 @@ export default defineConfig([
7293 platform : 'browser' ,
7394 target : [ ...config . target , 'es2019' ]
7495 } ,
96+ {
97+ ...config ,
98+ dts : false ,
99+ entry : {
100+ 'webchat-module' : './src/bundle/module.ts'
101+ } ,
102+ env : {
103+ ...config . env ,
104+ module_format : 'module'
105+ } ,
106+ esbuildPlugins : [ ...config . esbuildPlugins , externalCjsToEsmPlugin ( [ 'react' , 'react-dom' ] ) ] ,
107+ format : 'esm' ,
108+ platform : 'browser' ,
109+ shims : true ,
110+ splitting : false ,
111+ target : [ 'es2023' ] ,
112+ noExternal : [
113+ '@babel/runtime' ,
114+ 'botframework-directlinejs' ,
115+ 'botframework-webchat-api' ,
116+ 'botframework-webchat-component' ,
117+ 'botframework-webchat-core' ,
118+ 'classnames' ,
119+ 'core-js' ,
120+ 'math-random' ,
121+ 'mdast-util-from-markdown' ,
122+ 'memoize-one' ,
123+ 'prop-types' ,
124+ 'punycode' ,
125+ 'react-dom' ,
126+ 'react' ,
127+ 'url-search-params-polyfill'
128+ // TODO: these packages are needed for full build
129+ // decide how we should organize the full build:
130+ // 'micromark',
131+ // 'sanitize-html',
132+ // 'shiki',
133+ ]
134+ } ,
75135 {
76136 ...config ,
77137 format : 'esm'
0 commit comments