@@ -14,19 +14,20 @@ import Visualizer from 'rollup-plugin-visualizer';
14
14
* @param {string } dirName Output destination directory
15
15
*/
16
16
export function createBrowserUmdBuildConfig ( dirName = 'dist' ) {
17
+ const external = [
18
+ 'chalk' ,
19
+ ] ;
17
20
return {
18
21
input : 'src/main.js' ,
19
- external : [
20
- // external node modules
21
- 'chalk' ,
22
- // 'diff-match-patch'
23
- ] ,
22
+ external,
24
23
output : {
25
24
name : pkg . name ,
26
25
file : pkg . browser . replace ( / ^ d i s t \/ / , `${ dirName } /` ) ,
27
26
format : 'umd' ,
27
+ ...outputExternal ( external ) ,
28
28
} ,
29
29
plugins : [
30
+ createEmptyModuleDist ( ) ,
30
31
replace ( { 'process.browser' : true } ) ,
31
32
babel ( {
32
33
exclude : 'node_modules/**' ,
@@ -43,26 +44,28 @@ export function createBrowserUmdBuildConfig(dirName = 'dist') {
43
44
* @param {string } dirName Output destination directory
44
45
*/
45
46
export function createSlimBrowserUmdBuildConfig ( dirName = 'dist' ) {
47
+ const external = [
48
+ 'chalk' ,
49
+ 'diff-match-patch' ,
50
+ ] ;
46
51
return {
47
52
input : 'src/main.js' ,
48
- external : [
49
- // external node modules
50
- 'chalk' ,
51
- 'diff-match-patch' ,
52
- ] ,
53
+ external,
53
54
output : {
54
55
name : pkg . name ,
55
56
file : pkg . browser
56
57
. replace ( '.js' , '.slim.js' )
57
58
. replace ( / ^ d i s t \/ / , `${ dirName } /` ) ,
58
59
format : 'umd' ,
60
+ ...outputExternal ( external ) ,
59
61
} ,
60
62
plugins : [
61
63
new Visualizer ( {
62
64
filename : pkg . browser
63
65
. replace ( '.js' , '.slim.stats.html' )
64
66
. replace ( / ^ d i s t \/ / , `${ dirName } /` ) ,
65
67
} ) ,
68
+ createEmptyModuleDist ( ) ,
66
69
replace ( { 'process.browser' : true } ) ,
67
70
babel ( {
68
71
exclude : 'node_modules/**' ,
@@ -208,6 +211,9 @@ export const createBrowserTestBuild = (
208
211
. replace ( / ^ d i s t \/ / , `${ dirName } /` ) ,
209
212
sourcemap : true ,
210
213
format : 'umd' ,
214
+ globals : {
215
+ 'chalk' : 'chalk' ,
216
+ } ,
211
217
} ,
212
218
} ;
213
219
} ;
@@ -235,3 +241,37 @@ function copyFromFolderToDist(folder) {
235
241
} ;
236
242
} ;
237
243
}
244
+
245
+ function createEmptyModuleDist ( ) {
246
+ return function ( ) {
247
+ let executed = false ;
248
+ return {
249
+ ongenerate : ( ) => {
250
+ if ( executed ) {
251
+ return ;
252
+ }
253
+ const distFilename = path . join ( __dirname , 'dist' , 'empty.js' ) ;
254
+ mkdirp ( path . dirname ( distFilename ) ) ;
255
+ fs . writeFileSync ( distFilename , '' ) ;
256
+ console . log ( `dist/empty.js (created)` ) ;
257
+ executed = true ;
258
+ } ,
259
+ } ;
260
+ } ;
261
+ }
262
+
263
+ function outputExternal ( names ) {
264
+ if ( ! names || names . length < 1 ) {
265
+ return ;
266
+ }
267
+ return {
268
+ globals : names . reduce ( ( accum , name ) => ( {
269
+ ...accum ,
270
+ [ name ] : name ,
271
+ } ) , { } ) ,
272
+ paths : names . reduce ( ( accum , name ) => ( {
273
+ ...accum ,
274
+ [ name ] : './empty' ,
275
+ } ) , { } ) ,
276
+ } ;
277
+ }
0 commit comments