@@ -74,27 +74,28 @@ export default async function compile(fileName: string, options: BabelCompileOpt
74
74
if ( ( options . sourceMaps as string ) === 'true' ) {
75
75
options . sourceMaps = true ;
76
76
}
77
- let babelOptions =
78
- typeof esm === 'string' ? getESMTransformOption ( ) : typeof cjs === 'string' ? getCjsTransformOption ( ) : { } ;
77
+
78
+ let esmBabelOptions = getESMTransformOption ( ) ;
79
79
if ( useVue ) {
80
80
// @ts -ignore
81
- babelOptions . plugins ?. push ( babelPluginJsx . default ) ;
82
- babelOptions . sourceMaps = options . sourceMaps || babelOptions . sourceMaps ;
81
+ esmBabelOptions . plugins ?. push ( babelPluginJsx . default ) ;
83
82
}
84
- babelOptions . babelrc = true ;
85
- babelOptions . cwd = dt . projectDirectory ;
86
83
if ( envName ) {
87
- babelOptions = { } ;
88
- babelOptions . envName = envName ;
84
+ esmBabelOptions = { } ;
85
+ esmBabelOptions . envName = envName ;
89
86
}
87
+ esmBabelOptions . sourceMaps = options . sourceMaps || esmBabelOptions . sourceMaps ;
88
+ esmBabelOptions . babelrc = true ;
89
+ esmBabelOptions . cwd = dt . projectDirectory ;
90
+
90
91
if ( typeof esm === 'string' ) {
91
- babelOptions . sourceFileName = path . relative ( path . dirname ( dt . esm . path ) , fileName ) ;
92
- transform ( fileName , { ...babelOptions } )
92
+ esmBabelOptions . sourceFileName = path . relative ( path . dirname ( dt . esm . path ) , fileName ) ;
93
+ transform ( fileName , { ...esmBabelOptions } )
93
94
. then ( ( result ) => {
94
95
fs . ensureFileSync ( dt . esm . path ) ;
95
96
fs . writeFile ( dt . esm . path , result ?. code || '' ) ;
96
97
log . icon ( '🐶' ) . success ( `┈┈▶ \x1b[32;1m${ dt . folderFilePath } \x1b[0m => \x1b[34;1m${ dt . esm . fileName } \x1b[0m` ) ;
97
- if ( babelOptions . sourceMaps === 'both' || babelOptions . sourceMaps ) {
98
+ if ( esmBabelOptions . sourceMaps === 'both' || esmBabelOptions . sourceMaps ) {
98
99
if ( result ?. map ) {
99
100
const sourceMapPath = path . join ( dt . esm . path + '.map' ) ;
100
101
fs . writeFileSync ( sourceMapPath , JSON . stringify ( result ?. map , null , 2 ) ) ;
@@ -117,14 +118,28 @@ export default async function compile(fileName: string, options: BabelCompileOpt
117
118
}
118
119
} ) ;
119
120
}
121
+
122
+ let cjsBabelOptions = getCjsTransformOption ( ) ;
123
+ if ( useVue ) {
124
+ // @ts -ignore
125
+ cjsBabelOptions . plugins ?. push ( babelPluginJsx . default ) ;
126
+ }
127
+ if ( envName ) {
128
+ cjsBabelOptions = { } ;
129
+ cjsBabelOptions . envName = envName ;
130
+ }
131
+ cjsBabelOptions . sourceMaps = options . sourceMaps || cjsBabelOptions . sourceMaps ;
132
+ cjsBabelOptions . babelrc = true ;
133
+ cjsBabelOptions . cwd = dt . projectDirectory ;
134
+
120
135
if ( typeof cjs === 'string' ) {
121
- babelOptions . sourceFileName = path . relative ( path . dirname ( dt . cjs . path ) , fileName ) ;
122
- transform ( fileName , { ...babelOptions } )
136
+ cjsBabelOptions . sourceFileName = path . relative ( path . dirname ( dt . cjs . path ) , fileName ) ;
137
+ transform ( fileName , { ...cjsBabelOptions } )
123
138
. then ( ( result ) => {
124
139
fs . ensureFileSync ( dt . cjs . path ) ;
125
140
fs . writeFile ( dt . cjs . path , result ?. code || '' ) ;
126
141
log . icon ( '🐶' ) . success ( `┈┈▶ \x1b[33;1m${ dt . folderFilePath } \x1b[0m => \x1b[33;1m${ dt . cjs . fileName } \x1b[0m` ) ;
127
- if ( babelOptions . sourceMaps === 'both' || babelOptions . sourceMaps ) {
142
+ if ( cjsBabelOptions . sourceMaps === 'both' || cjsBabelOptions . sourceMaps ) {
128
143
if ( result ?. map ) {
129
144
const sourceMapPath = path . join ( dt . cjs . path + '.map' ) ;
130
145
fs . writeFileSync ( sourceMapPath , JSON . stringify ( result ?. map , null , 2 ) ) ;
0 commit comments