@@ -4,16 +4,16 @@ const { getPackageJson } = require("../projectHelpers");
4
4
exports . GenerateBundleStarterPlugin = ( function ( ) {
5
5
function GenerateBundleStarterPlugin ( bundles ) {
6
6
this . bundles = bundles ;
7
+ this . files = { } ;
7
8
} ;
8
9
9
10
GenerateBundleStarterPlugin . prototype . apply = function ( compiler ) {
10
- const plugin = this ;
11
- plugin . webpackContext = compiler . options . context ;
11
+ this . webpackContext = compiler . options . context ;
12
12
13
- compiler . plugin ( "emit" , function ( compilation , cb ) {
14
- compilation . assets [ "package.json" ] = plugin . generatePackageJson ( ) ;
15
- compilation . assets [ "starter.js" ] = plugin . generateStarterModule ( ) ;
16
- plugin . generateTnsJavaClasses ( compilation ) ;
13
+ compiler . plugin ( "emit" , ( compilation , cb ) => {
14
+ this . addAsset ( compilation , "package.json" , this . generatePackageJson ( ) ) ;
15
+ this . addAsset ( compilation , "starter.js" , this . generateStarterModule ( ) ) ;
16
+ this . generateTnsJavaClasses ( compilation ) ;
17
17
18
18
cb ( ) ;
19
19
} ) ;
@@ -24,23 +24,30 @@ exports.GenerateBundleStarterPlugin = (function() {
24
24
const isAndroid = path . indexOf ( "android" ) > - 1 ;
25
25
26
26
if ( isAndroid && ! compilation . assets [ "tns-java-classes.js" ] ) {
27
- compilation . assets [ "tns-java-classes.js" ] = new RawSource ( "" ) ;
27
+ this . addAsset ( compilation , "tns-java-classes.js" , "" ) ;
28
28
}
29
29
}
30
30
31
31
GenerateBundleStarterPlugin . prototype . generatePackageJson = function ( ) {
32
32
const packageJson = getPackageJson ( this . webpackContext ) ;
33
33
packageJson . main = "starter" ;
34
34
35
- return new RawSource ( JSON . stringify ( packageJson , null , 4 ) ) ;
35
+ return JSON . stringify ( packageJson , null , 4 ) ;
36
36
}
37
37
38
38
GenerateBundleStarterPlugin . prototype . generateStarterModule = function ( ) {
39
39
const moduleSource = this . bundles
40
40
. map ( bundle => `require("${ bundle } ")` )
41
41
. join ( "\n" ) ;
42
42
43
- return new RawSource ( moduleSource ) ;
43
+ return moduleSource ;
44
+ }
45
+
46
+ GenerateBundleStarterPlugin . prototype . addAsset = function ( compilation , name , content ) {
47
+ if ( this . files [ name ] !== content ) {
48
+ this . files [ name ] = content ;
49
+ compilation . assets [ name ] = new RawSource ( content ) ;
50
+ }
44
51
}
45
52
46
53
return GenerateBundleStarterPlugin ;
0 commit comments