1
+ /* eslint-disable require-unicode-regexp */
1
2
import path from 'path' ;
2
3
import { defineConfig } from 'tsup' ;
3
4
import baseConfig from '../../tsup.base.config' ;
@@ -50,6 +51,26 @@ const config: typeof baseConfig = {
50
51
]
51
52
} ;
52
53
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
+
53
74
export default defineConfig ( [
54
75
// Build IIFE before CJS/ESM to make npm start faster.
55
76
{
@@ -72,6 +93,45 @@ export default defineConfig([
72
93
platform : 'browser' ,
73
94
target : [ ...config . target , 'es2019' ]
74
95
} ,
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
+ } ,
75
135
{
76
136
...config ,
77
137
format : 'esm'
0 commit comments