@@ -22,7 +22,7 @@ const imageOptions = {
22
22
limit : 10000 ,
23
23
} ;
24
24
25
- function getWebpackConfig ( modules ) {
25
+ function getWebpackConfig ( modules , esm = false ) {
26
26
const pkg = require ( getProjectPath ( 'package.json' ) ) ;
27
27
const babelConfig = require ( './getBabelCommonConfig' ) ( modules || false ) ;
28
28
@@ -185,7 +185,7 @@ All rights reserved.
185
185
} ;
186
186
187
187
if ( process . env . RUN_ENV === 'PRODUCTION' ) {
188
- const entry = [ './index' ] ;
188
+ let entry = [ './index' ] ;
189
189
config . externals = [
190
190
{
191
191
vue : {
@@ -197,9 +197,25 @@ All rights reserved.
197
197
} ,
198
198
} ,
199
199
] ;
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
+
203
219
config . optimization = {
204
220
minimizer : [
205
221
new TerserPlugin ( {
@@ -213,7 +229,7 @@ All rights reserved.
213
229
// Development
214
230
const uncompressedConfig = merge ( { } , config , {
215
231
entry : {
216
- [ distFileBaseName ] : entry ,
232
+ [ entryName ] : entry ,
217
233
} ,
218
234
mode : 'development' ,
219
235
plugins : [
@@ -226,7 +242,7 @@ All rights reserved.
226
242
// Production
227
243
const prodConfig = merge ( { } , config , {
228
244
entry : {
229
- [ `${ distFileBaseName } .min` ] : entry ,
245
+ [ `${ entryName } .min` ] : entry ,
230
246
} ,
231
247
mode : 'production' ,
232
248
plugins : [
0 commit comments