@@ -31,6 +31,7 @@ function ensureImportFileExtension({ content, extension }) {
3131 */
3232export const tanstackViteConfig = ( options ) => {
3333 const outDir = options . outDir ?? 'dist'
34+ const cjs = options . cjs ?? true
3435
3536 return defineConfig ( {
3637 plugins : [
@@ -60,35 +61,37 @@ export const tanstackViteConfig = (options) => {
6061 }
6162 } ,
6263 } ) ,
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 ,
8487 ] ,
8588 build : {
8689 outDir,
8790 minify : false ,
8891 sourcemap : true ,
8992 lib : {
9093 entry : options . entry ,
91- formats : [ 'es' , 'cjs' ] ,
94+ formats : cjs ? [ 'es' , 'cjs' ] : [ 'es '] ,
9295 fileName : ( format ) => {
9396 if ( format === 'cjs' ) return 'cjs/[name].cjs'
9497 return 'esm/[name].js'
0 commit comments