11import path from 'path' ;
22import { defineConfig } from 'tsdown' ;
33import baseConfig from '../../tsdown.base.config' ;
4+ import type { Plugin as RollupPlugin } from 'rollup' ;
5+
6+ import pkg from './package.json'
7+
8+ const iifeDeps = Object . keys ( pkg . dependencies ) ;
49
510// Redirect import paths for "microsoft-cognitiveservices-speech-sdk(...)"
611// to point to es2015 distribution for all importing modules
7- const resolveCognitiveServicesToES2015 = {
12+ const resolveCognitiveServicesToES2015 : RollupPlugin = {
813 name : 'microsoft-cognitiveservices-speech-sdk' ,
9- setup ( build ) {
10- build . onResolve ( { filter : / m i c r o s o f t - c o g n i t i v e s e r v i c e s - s p e e c h - s d k .+ / u } , args => ( {
11- path : path . join ( process . cwd ( ) , '../../node_modules' , args . path . replace ( 'distrib/lib' , 'distrib/es2015' ) + '.js' )
12- } ) ) ;
14+ resolveId ( source ) {
15+ if ( / ^ m i c r o s o f t - c o g n i t i v e s e r v i c e s - s p e e c h - s d k .* $ / u. test ( source ) ) {
16+ let p = path . join ( process . cwd ( ) , '../../node_modules' , source . replace ( 'distrib/lib' , 'distrib/es2015' ) + '.js' ) ;
17+ p . endsWith ( 'node_modules/microsoft-cognitiveservices-speech-sdk.js' ) &&
18+ ( p = path . join (
19+ p ,
20+ '../microsoft-cognitiveservices-speech-sdk/distrib/es2015/microsoft.cognitiveservices.speech.sdk.js'
21+ ) ) ;
22+ return p ;
23+ }
24+ return null ;
1325 }
1426} ;
1527
1628// Redirect import paths for "react" and "react-dom"
17- const resolveReact = {
29+ const resolveReact : RollupPlugin = {
1830 name : 'isomorphic-react' ,
19- setup ( build ) {
20- build . onResolve ( { filter : / ^ ( r e a c t | r e a c t - d o m ) $ / u } , ( { path : pkgNamne } ) => ( {
21- path : path . join ( process . cwd ( ) , '../../node_modules' , `isomorphic-${ pkgNamne } /dist/${ pkgNamne } .js` )
22- } ) ) ;
31+ resolveId ( source ) {
32+ if ( source === 'react' || source === 'react-dom' ) {
33+ const p = path . join ( process . cwd ( ) , '../../node_modules' , `isomorphic-${ source } /dist/${ source } .js` ) ;
34+ return p ;
35+ }
36+ return null ;
2337 }
2438} ;
2539
@@ -38,7 +52,7 @@ const config: typeof baseConfig = {
3852 SPEECH_CONDUCT_OCSP_CHECK : '' ,
3953 SPEECH_OCSP_CACHE_ROOT : ''
4054 } ,
41- esbuildPlugins : [ ... ( baseConfig . esbuildPlugins || [ ] ) , resolveCognitiveServicesToES2015 ] ,
55+ plugins : [ resolveCognitiveServicesToES2015 ] ,
4256 noExternal : [
4357 '@babel/runtime' ,
4458 'memoize-one' ,
@@ -54,35 +68,54 @@ const config: typeof baseConfig = {
5468 ]
5569} ;
5670
71+ const iifeConfig = {
72+ ...config ,
73+ dts : false ,
74+ env : {
75+ ...config . env ,
76+ module_format : 'global'
77+ } ,
78+ plugins : [ ...config . plugins , resolveReact ] ,
79+ format : 'iife' ,
80+ platform : 'browser' ,
81+ target : [ ...config . target , 'es2019' ] ,
82+ noExternal : [
83+ // ...iifeDeps,
84+ ...config . noExternal ,
85+ ] ,
86+ outputOptions ( outputOptions ) {
87+ outputOptions . entryFileNames = '[name].js' ;
88+ return outputOptions ;
89+ } ,
90+ } ;
91+
5792export default defineConfig ( [
5893 // Build IIFE before CJS/ESM to make npm start faster.
5994 {
60- ...config ,
61- dts : false ,
95+ ...iifeConfig ,
6296 entry : {
63- webchat : './src/bundle/index.ts' ,
64- 'webchat-es5' : './src/bundle/index-es5.ts' ,
6597 'webchat-minimal' : './src/bundle/index-minimal.ts'
66- } ,
67- env : {
68- ...config . env ,
69- module_format : 'global'
70- } ,
71- esbuildPlugins : [ ...config . esbuildPlugins , resolveReact ] ,
72- format : 'iife' ,
73- outExtension ( ) {
74- return { js : '.js' } ;
75- } ,
76- platform : 'browser' ,
77- target : [ ...config . target , 'es2019' ]
98+ }
7899 } ,
79100 {
80- ...config ,
81- format : 'esm'
101+ ...iifeConfig ,
102+ entry : {
103+ 'webchat' : './src/bundle/index.ts'
104+ }
105+ } ,
106+ {
107+ ...iifeConfig ,
108+ entry : {
109+ 'webchat-es5' : './src/bundle/index-es5.ts'
110+ }
82111 } ,
83112 {
84113 ...config ,
85- format : 'cjs' ,
86- target : [ ...config . target , 'es2019' ]
87- }
114+ format : 'esm'
115+ } ,
116+ // {
117+ // ...config,
118+ // format: 'cjs',
119+ // target: [...config.target, 'es2019']
120+ // }
88121] ) ;
0 commit comments