@@ -4,6 +4,8 @@ import { isolatedDeclaration } from 'oxc-transform';
4
4
import type { Options } from 'tsup' ;
5
5
import { defineConfig } from 'tsup' ;
6
6
7
+ const pkgName = 'react-querybuilder_chakra2' ;
8
+
7
9
const generateDTS = async ( projDir : string ) : Promise < void > => {
8
10
const g = new Bun . Glob ( '**/*.{ts,tsx}' ) ;
9
11
@@ -56,81 +58,73 @@ const generateDTS = async (projDir: string): Promise<void> => {
56
58
console . log ( `${ fileCount } DTS files generated.` ) ;
57
59
} ;
58
60
59
- const getCjsIndexWriter = ( pkgName : string , debug ?: boolean ) => async ( ) : Promise < void > => {
60
- await writeFile (
61
- `dist/cjs/${ debug ? 'debug' : 'index' } .js` ,
62
- `'use strict';
61
+ export default defineConfig ( async options => {
62
+ const entryPoint = `src/index.tsx` ;
63
+
64
+ const commonOptions = {
65
+ entry : { [ pkgName ] : entryPoint } ,
66
+ sourcemap : true ,
67
+ ...options ,
68
+ } satisfies Options ;
69
+
70
+ const productionOptions = {
71
+ minify : true ,
72
+ replaceNodeEnv : true ,
73
+ } satisfies Options ;
74
+
75
+ const opts : Options [ ] = [
76
+ // ESM, standard bundler dev, embedded `process` references
77
+ {
78
+ ...commonOptions ,
79
+ format : 'esm' ,
80
+ clean : true ,
81
+ onSuccess : ( ) => generateDTS ( import . meta. dir ) ,
82
+ } ,
83
+ // ESM, Webpack 4 support. Target ES2017 syntax to compile away optional chaining and spreads
84
+ {
85
+ ...commonOptions ,
86
+ entry : { [ `${ pkgName } .legacy-esm` ] : entryPoint } ,
87
+ // ESBuild outputs `'.mjs'` by default for the 'esm' format. Force '.js'
88
+ outExtension : ( ) => ( { js : '.js' } ) ,
89
+ target : 'es2017' ,
90
+ format : 'esm' ,
91
+ } ,
92
+ // ESM for use in browsers. Minified, with `process` compiled away
93
+ {
94
+ ...commonOptions ,
95
+ ...productionOptions ,
96
+ entry : { [ `${ pkgName } .production` ] : entryPoint } ,
97
+ format : 'esm' ,
98
+ outExtension : ( ) => ( { js : '.mjs' } ) ,
99
+ } ,
100
+ // CJS development
101
+ {
102
+ ...commonOptions ,
103
+ entry : { [ `${ pkgName } .cjs.development` ] : entryPoint } ,
104
+ format : 'cjs' ,
105
+ outDir : './dist/cjs/' ,
106
+ } ,
107
+ // CJS production
108
+ {
109
+ ...commonOptions ,
110
+ ...productionOptions ,
111
+ entry : { [ `${ pkgName } .cjs.production` ] : entryPoint } ,
112
+ format : 'cjs' ,
113
+ outDir : './dist/cjs/' ,
114
+ onSuccess : async ( ) => {
115
+ await writeFile (
116
+ `dist/cjs/index.js` ,
117
+ `'use strict';
63
118
if (process.env.NODE_ENV === 'production') {
64
- module.exports = require('./${ pkgName } .cjs.production${ debug ? '.debug' : '' } .js');
119
+ module.exports = require('./${ pkgName } .cjs.production.js');
65
120
} else {
66
- module.exports = require('./${ pkgName } .cjs.development${ debug ? '.debug' : '' } .js');
121
+ module.exports = require('./${ pkgName } .cjs.development.js');
67
122
}
68
123
`
69
- ) ;
70
- } ;
71
-
72
- const tsupCommonConfig = ( sourceDir : string ) =>
73
- ( async options => {
74
- const pkgName = `react-querybuilder${ sourceDir . endsWith ( 'react-querybuilder' ) ? '' : `_${ sourceDir . split ( '/' ) . pop ( ) } ` } ` ;
75
- const x = ( await Bun . file ( path . join ( sourceDir + '/src/index.tsx' ) ) . exists ( ) ) ? 'x' : '' ;
76
- const entryPoint = `src/index.ts${ x } ` ;
77
-
78
- const commonOptions = {
79
- entry : { [ pkgName ] : entryPoint } ,
80
- sourcemap : true ,
81
- esbuildPlugins : [ ] ,
82
- ...options ,
83
- } satisfies Options ;
84
-
85
- const productionOptions = {
86
- minify : true ,
87
- replaceNodeEnv : true ,
88
- } satisfies Options ;
89
-
90
- const opts : Options [ ] = [
91
- // ESM, standard bundler dev, embedded `process` references
92
- {
93
- ...commonOptions ,
94
- format : 'esm' ,
95
- clean : true ,
96
- onSuccess : ( ) => generateDTS ( sourceDir ) ,
124
+ ) ;
97
125
} ,
98
- // ESM, Webpack 4 support. Target ES2017 syntax to compile away optional chaining and spreads
99
- {
100
- ...commonOptions ,
101
- entry : { [ `${ pkgName } .legacy-esm` ] : entryPoint } ,
102
- // ESBuild outputs `'.mjs'` by default for the 'esm' format. Force '.js'
103
- outExtension : ( ) => ( { js : '.js' } ) ,
104
- target : 'es2017' ,
105
- format : 'esm' ,
106
- } ,
107
- // ESM for use in browsers. Minified, with `process` compiled away
108
- {
109
- ...commonOptions ,
110
- ...productionOptions ,
111
- entry : { [ `${ pkgName } .production` ] : entryPoint } ,
112
- format : 'esm' ,
113
- outExtension : ( ) => ( { js : '.mjs' } ) ,
114
- } ,
115
- // CJS development
116
- {
117
- ...commonOptions ,
118
- entry : { [ `${ pkgName } .cjs.development` ] : entryPoint } ,
119
- format : 'cjs' ,
120
- outDir : './dist/cjs/' ,
121
- } ,
122
- // CJS production
123
- {
124
- ...commonOptions ,
125
- ...productionOptions ,
126
- entry : { [ `${ pkgName } .cjs.production` ] : entryPoint } ,
127
- format : 'cjs' ,
128
- outDir : './dist/cjs/' ,
129
- onSuccess : getCjsIndexWriter ( pkgName , false ) ,
130
- } ,
131
- ] ;
132
-
133
- return opts ;
134
- } ) as ( options : Options ) => Promise < Options [ ] > ;
126
+ } ,
127
+ ] ;
135
128
136
- export default defineConfig ( tsupCommonConfig ( import . meta. dir ) ) ;
129
+ return opts ;
130
+ } ) ;
0 commit comments