1
1
const webpack = require ( 'webpack' ) ;
2
2
const LavaMoatPlugin = require ( '@lavamoat/webpack' )
3
+ const fs = require ( 'fs' ) ;
4
+ const path = require ( 'path' ) ;
3
5
4
6
module . exports = function override ( config , env ) {
5
7
config . optimization = {
6
8
...config . optimization ,
7
- minimize : false
9
+ minimize : false ,
10
+ concatenateModules : false
8
11
} ;
9
12
10
13
config . resolve . fallback = {
@@ -21,26 +24,93 @@ module.exports = function override(config, env) {
21
24
vm : require . resolve ( 'vm-browserify' ) ,
22
25
} ;
23
26
24
- config . plugins = [
25
- new LavaMoatPlugin ( {
26
- writeAutoConfig : true ,
27
- inlineLockdown : / i n d e x \. j s / ,
28
- lockdown : {
29
- consoleTaming : 'unsafe' ,
30
- errorTrapping : 'none' ,
31
- unhandledRejectionTrapping : 'none' ,
32
- overrideTaming : 'moderate' ,
33
- }
34
- } ) ,
35
- ...config . plugins ,
36
- new webpack . ProvidePlugin ( {
37
- process : 'process/browser' ,
38
- Buffer : [ 'buffer' , 'Buffer' ] ,
39
- } ) ,
40
- new webpack . DefinePlugin ( {
41
- 'process.env' : JSON . stringify ( process . env ) ,
42
- } ) ,
43
- ] ;
27
+ // Read the generated policy file
28
+ let policy = { } ;
29
+ const policyPath = path . join ( __dirname , 'lavamoat' , 'webpack' ) ;
30
+ const policyFile = path . join ( policyPath , 'policy.json' ) ;
31
+
32
+ try {
33
+ policy = JSON . parse ( fs . readFileSync ( policyFile , 'utf8' ) ) ;
34
+ } catch ( err ) {
35
+ console . warn ( 'No existing LavaMoat policy found, will generate one' ) ;
36
+ }
37
+
38
+ // Add custom policies
39
+ /* if (policy.resources) {
40
+ // WalletConnect policy
41
+ if (!policy.resources['@walletconnect /core']) {
42
+ policy.resources['@walletconnect /core'] = {
43
+ globals: {
44
+ ArrayBuffer: true,
45
+ Uint8Array: true,
46
+ Object: true,
47
+ 'Object.prototype': true,
48
+ 'Object.getPrototypeOf': true,
49
+ Symbol: true,
50
+ 'Function.prototype': true
51
+ }
52
+ };
53
+ }
54
+
55
+ // React policy
56
+ if (!policy.resources['react']) {
57
+ policy.resources['react'] = {
58
+ globals: {
59
+ Object: true,
60
+ 'Object.prototype': true,
61
+ 'Function.prototype': true
62
+ }
63
+ };
64
+ }
65
+
66
+ // Lodash policy
67
+ if (!policy.resources['lodash']) {
68
+ policy.resources['lodash'] = {
69
+ globals: {
70
+ Object: true,
71
+ 'Object.prototype': true,
72
+ 'Function.prototype': true
73
+ }
74
+ };
75
+ }
76
+ }*/
77
+
78
+ // Don't use LavaMoat when running in electron
79
+ if ( process . env . ELECTRON_RUN === 'true' ) {
80
+ config . plugins = [
81
+ ...config . plugins ,
82
+ new webpack . ProvidePlugin ( {
83
+ process : 'process/browser' ,
84
+ Buffer : [ 'buffer' , 'Buffer' ] ,
85
+ } ) ,
86
+ new webpack . DefinePlugin ( {
87
+ 'process.env' : JSON . stringify ( process . env ) ,
88
+ } ) ,
89
+ ] ;
90
+ } else {
91
+ config . plugins = [
92
+ new LavaMoatPlugin ( {
93
+ generatePolicy : true ,
94
+ HtmlWebpackPluginInterop : true ,
95
+ readableResourceIds : true ,
96
+ diagnosticsVerbosity : 1 ,
97
+ lockdown : {
98
+ consoleTaming : 'unsafe' ,
99
+ errorTrapping : 'none' ,
100
+ unhandledRejectionTrapping : 'none' ,
101
+ overrideTaming : 'severe' ,
102
+ }
103
+ } ) ,
104
+ ...config . plugins ,
105
+ new webpack . ProvidePlugin ( {
106
+ process : 'process/browser' ,
107
+ Buffer : [ 'buffer' , 'Buffer' ] ,
108
+ } ) ,
109
+ new webpack . DefinePlugin ( {
110
+ 'process.env' : JSON . stringify ( process . env ) ,
111
+ } ) ,
112
+ ] ;
113
+ }
44
114
45
115
config . module . rules . push ( {
46
116
test : / \. m ? j s / ,
0 commit comments