@@ -31,6 +31,7 @@ function ensureImportFileExtension({ content, extension }) {
31
31
*/
32
32
export const tanstackViteConfig = ( options ) => {
33
33
const outDir = options . outDir ?? 'dist'
34
+ const cjs = options . cjs ?? true
34
35
35
36
return defineConfig ( {
36
37
plugins : [
@@ -60,35 +61,37 @@ export const tanstackViteConfig = (options) => {
60
61
}
61
62
} ,
62
63
} ) ,
63
- dts ( {
64
- outDir : `${ outDir } /cjs` ,
65
- entryRoot : options . srcDir ,
66
- include : options . srcDir ,
67
- exclude : options . exclude ,
68
- tsconfigPath : options . tsconfigPath ,
69
- compilerOptions : {
70
- module : 1 , // CommonJS
71
- declarationMap : false ,
72
- } ,
73
- beforeWriteFile : ( filePath , content ) => ( {
74
- filePath : filePath . replace ( '.d.ts' , '.d.cts' ) ,
75
- content : ensureImportFileExtension ( { content, extension : 'cjs' } ) ,
76
- } ) ,
77
- afterDiagnostic : ( diagnostics ) => {
78
- if ( diagnostics . length > 0 ) {
79
- console . error ( 'Please fix the above type errors' )
80
- process . exit ( 1 )
81
- }
82
- } ,
83
- } ) ,
64
+ cjs
65
+ ? dts ( {
66
+ outDir : `${ outDir } /cjs` ,
67
+ entryRoot : options . srcDir ,
68
+ include : options . srcDir ,
69
+ exclude : options . exclude ,
70
+ tsconfigPath : options . tsconfigPath ,
71
+ compilerOptions : {
72
+ module : 1 , // CommonJS
73
+ declarationMap : false ,
74
+ } ,
75
+ beforeWriteFile : ( filePath , content ) => ( {
76
+ filePath : filePath . replace ( '.d.ts' , '.d.cts' ) ,
77
+ content : ensureImportFileExtension ( { content, extension : 'cjs' } ) ,
78
+ } ) ,
79
+ afterDiagnostic : ( diagnostics ) => {
80
+ if ( diagnostics . length > 0 ) {
81
+ console . error ( 'Please fix the above type errors' )
82
+ process . exit ( 1 )
83
+ }
84
+ } ,
85
+ } )
86
+ : undefined ,
84
87
] ,
85
88
build : {
86
89
outDir,
87
90
minify : false ,
88
91
sourcemap : true ,
89
92
lib : {
90
93
entry : options . entry ,
91
- formats : [ 'es' , 'cjs' ] ,
94
+ formats : cjs ? [ 'es' , 'cjs' ] : [ 'es '] ,
92
95
fileName : ( format ) => {
93
96
if ( format === 'cjs' ) return 'cjs/[name].cjs'
94
97
return 'esm/[name].js'
0 commit comments