@@ -22,7 +22,7 @@ const imageOptions = {
2222 limit : 10000 ,
2323} ;
2424
25- function getWebpackConfig ( modules ) {
25+ function getWebpackConfig ( modules , esm = false ) {
2626 const pkg = require ( getProjectPath ( 'package.json' ) ) ;
2727 const babelConfig = require ( './getBabelCommonConfig' ) ( modules || false ) ;
2828
@@ -185,7 +185,7 @@ All rights reserved.
185185 } ;
186186
187187 if ( process . env . RUN_ENV === 'PRODUCTION' ) {
188- const entry = [ './index' ] ;
188+ let entry = [ './index' ] ;
189189 config . externals = [
190190 {
191191 vue : {
@@ -197,9 +197,25 @@ All rights reserved.
197197 } ,
198198 } ,
199199 ] ;
200- config . output . library = distFileBaseName ;
201- config . output . libraryTarget = 'umd' ;
202- config . output . globalObject = 'this' ;
200+ if ( esm ) {
201+ entry = [ './index.esm' ] ;
202+ config . experiments = {
203+ ...config . experiments ,
204+ outputModule : true ,
205+ } ;
206+ config . output . chunkFormat = 'module' ;
207+ config . output . library = {
208+ type : 'module' ,
209+ } ;
210+ config . target = 'es2019' ;
211+ } else {
212+ config . output . libraryTarget = 'umd' ;
213+ config . output . library = distFileBaseName ;
214+ config . output . globalObject = 'this' ;
215+ }
216+
217+ const entryName = esm ? `${ distFileBaseName } .esm` : distFileBaseName ;
218+
203219 config . optimization = {
204220 minimizer : [
205221 new TerserPlugin ( {
@@ -213,7 +229,7 @@ All rights reserved.
213229 // Development
214230 const uncompressedConfig = merge ( { } , config , {
215231 entry : {
216- [ distFileBaseName ] : entry ,
232+ [ entryName ] : entry ,
217233 } ,
218234 mode : 'development' ,
219235 plugins : [
@@ -226,7 +242,7 @@ All rights reserved.
226242 // Production
227243 const prodConfig = merge ( { } , config , {
228244 entry : {
229- [ `${ distFileBaseName } .min` ] : entry ,
245+ [ `${ entryName } .min` ] : entry ,
230246 } ,
231247 mode : 'production' ,
232248 plugins : [
0 commit comments