@@ -10,8 +10,9 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
10
10
const MiniCssExtractPlugin = require ( 'mini-css-extract-plugin' ) ;
11
11
const OptimizeCSSPlugin = require ( 'optimize-css-assets-webpack-plugin' ) ;
12
12
13
+ const isEsm = process . env . ESM ;
13
14
const isExampleEnv = process . env . EXAMPLE_ENV ;
14
- const distPath = '../lib' ;
15
+ const distPath = isEsm ? '../esm' : '../lib' ;
15
16
16
17
const env = process . env . NODE_ENV === 'testing' ? require ( '../config/test.env' ) : config . build . env ;
17
18
@@ -32,21 +33,35 @@ const webpackConfig = merge(baseWebpackConfig, {
32
33
} ) ;
33
34
34
35
if ( ! isExampleEnv ) {
35
- webpackConfig . entry = {
36
- 'vue-json-pretty' : './src/index.ts' ,
37
- } ;
38
36
webpackConfig . output = {
39
37
path : path . resolve ( __dirname , distPath ) ,
40
38
filename : `${ distPath } /[name].js` ,
41
- globalObject : 'this' ,
42
- library : 'VueJsonPretty' ,
43
- libraryTarget : 'umd' ,
44
39
} ;
40
+ if ( isEsm ) {
41
+ webpackConfig . entry = {
42
+ 'vue-json-pretty' : './src/index.ts' ,
43
+ } ;
44
+ webpackConfig . experiments = {
45
+ outputModule : true ,
46
+ } ;
47
+ webpackConfig . output . library = { type : 'module' } ;
48
+ webpackConfig . output . chunkFormat = 'module' ;
49
+ webpackConfig . target = 'es2019' ;
50
+ } else {
51
+ webpackConfig . entry = {
52
+ 'vue-json-pretty' : './src/index.ts' ,
53
+ } ;
54
+ webpackConfig . output . globalObject = 'this' ;
55
+ webpackConfig . output . library = 'VueJsonPretty' ;
56
+ webpackConfig . output . libraryTarget = 'umd' ;
57
+ }
45
58
webpackConfig . externals = {
46
59
vue : {
47
60
root : 'Vue' ,
48
- commonjs : 'vue' ,
49
61
commonjs2 : 'vue' ,
62
+ commonjs : 'vue' ,
63
+ amd : 'vue' ,
64
+ module : 'vue' ,
50
65
} ,
51
66
} ;
52
67
webpackConfig . plugins . push (
0 commit comments