@@ -30,48 +30,45 @@ const onwarn = (warning, warn) => {
30
30
}
31
31
} ;
32
32
33
- let plugins = [ resolve ( { dedupe : 'three' } ) , replace ( { 'Reflect.decorate' : 'undefined' } ) ] ;
33
+ let commonPlugins = [
34
+ resolve ( { dedupe : 'three' } ) ,
35
+ replace ( { 'Reflect.decorate' : 'undefined' } )
36
+ ] ;
34
37
35
38
const watchFiles = [ 'lib/**' ] ;
36
39
37
- const outputOptions = [
38
- {
39
- input : './lib/model-viewer.js' ,
40
- output : {
41
- file : './dist/model-viewer.js' ,
42
- sourcemap : true ,
43
- format : 'esm' ,
44
- name : 'ModelViewerElement' ,
45
- } ,
46
- watch : {
47
- include : watchFiles ,
48
- } ,
49
- plugins,
50
- onwarn,
51
- } ,
52
- {
40
+ const createModelViewerOutput = ( file , format , plugins = commonPlugins , external = [ ] ) => {
41
+ const globals = external . reduce ( ( acc , mod ) => {
42
+ acc [ mod ] = mod ; // Assuming global variable names are the same as module names
43
+ return acc ;
44
+ } , { } ) ;
45
+
46
+ return {
53
47
input : './lib/model-viewer.js' ,
54
48
output : {
55
- file : './dist/model-viewer-module.js' ,
49
+ file,
50
+ format,
56
51
sourcemap : true ,
57
- format : 'esm' ,
58
52
name : 'ModelViewerElement' ,
59
- globals : {
60
- 'three' : 'three' ,
61
- } ,
53
+ globals
62
54
} ,
63
- external : [ 'three' ] ,
55
+ external,
64
56
watch : {
65
- include : watchFiles ,
57
+ include : watchFiles
66
58
} ,
67
59
plugins,
68
- onwarn,
69
- }
60
+ onwarn
61
+ } ;
62
+ } ;
63
+
64
+ const outputOptions = [
65
+ createModelViewerOutput ( './dist/model-viewer.js' , 'esm' ) ,
66
+ createModelViewerOutput ( './dist/model-viewer-module.js' , 'esm' , commonPlugins , [ 'three' ] )
70
67
] ;
71
68
72
69
if ( NODE_ENV !== 'development' ) {
73
70
const pluginsIE11 = [
74
- ...plugins ,
71
+ ...commonPlugins ,
75
72
commonjs ( ) ,
76
73
polyfill ( [ 'object.values/auto' ] ) ,
77
74
cleanup ( {
@@ -84,114 +81,21 @@ if (NODE_ENV !== 'development') {
84
81
85
82
// IE11 does not support modules, so they are removed here, as well as in a
86
83
// dedicated unit test build which is needed for the same reason.
87
- outputOptions . push ( {
88
- input : './lib/model-viewer.js' ,
89
- output : {
90
- file : './dist/model-viewer-umd.js' ,
91
- sourcemap : true ,
92
- format : 'umd' ,
93
- name : 'ModelViewerElement' ,
94
- } ,
95
- watch : {
96
- include : watchFiles ,
97
- } ,
98
- plugins : pluginsIE11 ,
99
- onwarn,
100
- } ) ;
101
-
102
- /** Bundled w/o three */
103
-
104
- // IE11 does not support modules, so they are removed here, as well as in a
105
- // dedicated unit test build which is needed for the same reason.
106
- outputOptions . push ( {
107
- input : './lib/model-viewer.js' ,
108
- output : {
109
- file : './dist/model-viewer-module-umd.js' ,
110
- sourcemap : true ,
111
- format : 'umd' ,
112
- name : 'ModelViewerElement' ,
113
- globals : {
114
- 'three' : 'three' ,
115
- } ,
116
- } ,
117
- external : [ 'three' ] ,
118
- watch : {
119
- include : watchFiles ,
120
- } ,
121
- plugins : pluginsIE11 ,
122
- onwarn,
123
- } ) ;
84
+ outputOptions . push (
85
+ createModelViewerOutput ( './dist/model-viewer-umd.js' , 'umd' , pluginsIE11 ) ,
86
+ /** Bundled w/o three */
87
+ createModelViewerOutput ( './dist/model-viewer-module-umd.js' , 'umd' , pluginsIE11 , [ 'three' ] )
88
+ ) ;
124
89
125
90
// Minified Versions
126
- plugins = [ ...plugins , terser ( ) ] ;
127
-
128
- outputOptions . push ( {
129
- input : './dist/model-viewer.js' ,
130
- output : {
131
- file : './dist/model-viewer.min.js' ,
132
- sourcemap : true ,
133
- format : 'esm' ,
134
- name : 'ModelViewerElement' ,
135
- } ,
136
- watch : {
137
- include : watchFiles ,
138
- } ,
139
- plugins,
140
- onwarn,
141
- } ) ;
142
-
143
- outputOptions . push ( {
144
- input : './dist/model-viewer-umd.js' ,
145
- output : {
146
- file : './dist/model-viewer-umd.min.js' ,
147
- sourcemap : true ,
148
- format : 'umd' ,
149
- name : 'ModelViewerElement' ,
150
- } ,
151
- watch : {
152
- include : watchFiles ,
153
- } ,
154
- plugins,
155
- onwarn,
156
- } ) ;
157
-
158
- outputOptions . push ( {
159
- input : './dist/model-viewer-module.js' ,
160
- output : {
161
- file : './dist/model-viewer-module.min.js' ,
162
- sourcemap : true ,
163
- format : 'esm' ,
164
- name : 'ModelViewerElement' ,
165
- globals : {
166
- 'three' : 'three' ,
167
- } ,
168
- } ,
169
- external : [ 'three' ] ,
170
- watch : {
171
- include : watchFiles ,
172
- } ,
173
- plugins,
174
- onwarn,
175
- } ) ;
176
-
177
- outputOptions . push ( {
178
- input : './dist/model-viewer-module-umd.js' ,
179
- output : {
180
- file : './dist/model-viewer-module-umd.min.js' ,
181
- sourcemap : true ,
182
- format : 'umd' ,
183
- name : 'ModelViewerElement' ,
184
- globals : {
185
- 'three' : 'three' ,
186
- } ,
187
- } ,
188
- external : [ 'three' ] ,
189
- watch : {
190
- include : watchFiles ,
191
- } ,
192
- plugins,
193
- onwarn,
194
- } ) ;
91
+ const minifiedPlugins = [ ...commonPlugins , terser ( ) ] ;
92
+
93
+ outputOptions . push (
94
+ createModelViewerOutput ( './dist/model-viewer.min.js' , 'esm' , minifiedPlugins ) ,
95
+ createModelViewerOutput ( './dist/model-viewer-umd.min.js' , 'umd' , minifiedPlugins ) ,
96
+ createModelViewerOutput ( './dist/model-viewer-module.min.js' , 'esm' , minifiedPlugins , [ 'three' ] ) ,
97
+ createModelViewerOutput ( './dist/model-viewer-module-umd.min.js' , 'umd' , minifiedPlugins , [ 'three' ] )
98
+ ) ;
195
99
196
100
outputOptions . push ( {
197
101
input : './lib/model-viewer.d.ts' ,
0 commit comments