@@ -6,59 +6,42 @@ import * as path from 'path';
6
6
import { fileURLToPath } from 'url' ;
7
7
import commenting from 'commenting' ;
8
8
import { readFileSync } from 'fs' ;
9
- import { sync as rimrafSync } from 'rimraf' ;
10
9
11
10
const dirName = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
12
-
13
- const vendorFileName = 'd3-scale.js' ;
14
11
const vendorFolder = path . join ( dirName , '../lib/components/internal/vendor' ) ;
15
- const vendorFile = path . join ( vendorFolder , vendorFileName ) ;
16
- const d3LicencesFile = path . join ( dirName , 'generated-third-party-licenses.txt' ) ;
12
+ const licensesFile = path . join ( dirName , 'generated-third-party-licenses.txt' ) ;
17
13
18
- export default {
19
- input : vendorFile ,
14
+ export default [ 'd3-scale' , 'react-virtual' ] . map ( entry => ( {
15
+ input : `./src/internal/vendor/ ${ entry } .js` ,
20
16
output : {
21
- file : vendorFile ,
17
+ dir : vendorFolder ,
22
18
format : 'es' ,
23
19
} ,
20
+ external : [ 'react' , 'react-dom' ] ,
24
21
plugins : [
25
22
resolve ( {
26
23
extensions : [ '.js' ] ,
27
24
} ) ,
28
25
license ( {
29
26
thirdParty : {
30
27
output : {
31
- file : d3LicencesFile ,
28
+ file : path . join ( dirName , `generated-third-party-licenses- ${ entry } .txt` ) ,
32
29
encoding : 'utf-8' ,
33
30
} ,
34
31
} ,
35
32
} ) ,
36
- attach3rdPartyLicenses ( ) ,
37
- removeVendorFolder ( ) ,
33
+ attach3rdPartyLicenses ( entry ) ,
38
34
] ,
39
- } ;
40
-
41
- function removeVendorFolder ( ) {
42
- return {
43
- name : 'remove-vendor-folder' ,
44
- generateBundle : {
45
- sequential : true ,
46
- order : 'pre' ,
47
- handler ( ) {
48
- rimrafSync ( vendorFolder ) ;
49
- } ,
50
- } ,
51
- } ;
52
- }
35
+ } ) ) ;
53
36
54
37
// Rollup plugin which prepends the generated 3rd party licences content to the bundled code before writing the file.
55
- function attach3rdPartyLicenses ( ) {
38
+ function attach3rdPartyLicenses ( entry ) {
56
39
return {
57
40
name : 'attach-3rd-party-licences' ,
58
41
generateBundle ( _options , bundle ) {
59
- const content = readFileSync ( d3LicencesFile , 'utf8' ) ;
42
+ const content = readFileSync ( path . join ( dirName , `generated-third-party-licenses- ${ entry } .txt` ) , 'utf8' ) ;
60
43
const comment = commenting ( content , { extension : '.js' } ) ;
61
- bundle [ vendorFileName ] . code = `${ comment } ${ bundle [ vendorFileName ] . code } ` ;
44
+ bundle [ ` ${ entry } .js` ] . code = `${ comment } ${ bundle [ ` ${ entry } .js` ] . code } ` ;
62
45
} ,
63
46
} ;
64
47
}
0 commit comments