4
4
var path = require ( 'path' ) ;
5
5
var webpack = require ( 'webpack' ) ;
6
6
const dotenv = require ( 'dotenv' ) ;
7
+ const root = path . resolve ( __dirname , '..' ) ;
8
+ const MiniCssExtractPlugin = require ( "mini-css-extract-plugin" ) ;
9
+
7
10
dotenv . config ( ) ;
8
- var ForemanVendorPlugin = require ( '@theforeman/vendor' )
9
- . WebpackForemanVendorPlugin ;
10
11
var StatsWriterPlugin = require ( 'webpack-stats-plugin' ) . StatsWriterPlugin ;
11
12
var vendorEntry = require ( './webpack.vendor' ) ;
12
13
var fs = require ( 'fs' ) ;
@@ -15,6 +16,18 @@ var pluginUtils = require('../script/plugin_webpack_directories');
15
16
var { generateExportsFile } = require ( '../webpack/assets/javascripts/exportAll' ) ;
16
17
var CompressionPlugin = require ( 'compression-webpack-plugin' ) ;
17
18
19
+ const packageJsonPath = path . resolve ( __dirname , '..' , 'package.json' ) ;
20
+ const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf8' ) ) ;
21
+ const dependencies = packageJson . dependencies || { } ;
22
+ const devDependencies = packageJson . devDependencies || { } ;
23
+ const allDependencies = { ...dependencies , ...devDependencies } ;
24
+ const shared = isPlugin => Object . keys ( allDependencies ) . map ( dep => ( {
25
+ [ dep ] : {
26
+ eager : ! isPlugin , // core should load all dependencies eagerly so they will be available for plugins
27
+ singleton : true ,
28
+ requiredVersion : allDependencies [ dep ] ,
29
+ } } ) ) ;
30
+
18
31
class AddRuntimeRequirement {
19
32
// to avoid "webpackRequire.l is not a function" error
20
33
// enables use of webpack require inside promise new promise
@@ -79,11 +92,18 @@ const commonConfig = function() {
79
92
os : require . resolve ( 'os-browserify' ) ,
80
93
} ,
81
94
alias : {
95
+ 'patternfly-react$' : path . resolve ( __dirname , '..' , 'node_modules/patternfly-react/dist/js/index.js' ) , // to avoid circular dependency in dist/esm
96
+ '/node_modules/jquery' : path . resolve ( __dirname , '..' , 'webpack/assets/javascripts/jquery.js' ) ,
97
+ 'jquery' : path . resolve ( __dirname , '..' , 'webpack/assets/javascripts/jquery.js' ) ,
82
98
foremanReact : path . join (
83
99
__dirname ,
84
100
'../webpack/assets/javascripts/react_app'
85
101
) ,
102
+ 'react/jsx-runtime' : 'react/jsx-runtime.js' , // for react-dnd
103
+ 'react/jsx-dev-runtime' : 'react/jsx-dev-runtime.js' , // for react-dnd
104
+
86
105
} ,
106
+
87
107
} ,
88
108
resolveLoader : {
89
109
modules : [ path . resolve ( __dirname , '..' , 'node_modules' ) ] ,
@@ -117,9 +137,6 @@ const commonConfig = function() {
117
137
] ,
118
138
} ,
119
139
plugins : [
120
- new ForemanVendorPlugin ( {
121
- mode,
122
- } ) ,
123
140
new webpack . DefinePlugin ( {
124
141
'process.env' : {
125
142
NODE_ENV : JSON . stringify ( mode ) ,
@@ -160,13 +177,18 @@ const coreConfig = function() {
160
177
}
161
178
162
179
config . entry = {
180
+ /* keep bundle entry files and reactExports seperate to avoid late loading issues of mixed files, import in react_app only from react_app and node_modules */
163
181
bundle : { import : bundleEntry , dependOn : [ 'vendor' , 'reactExports' ] } ,
164
- vendor : vendorEntry ,
165
- reactExports : path . join (
182
+ reactExports : {
183
+ import : path . join (
166
184
__dirname ,
167
185
'..' ,
168
186
'webpack/assets/javascripts/all_react_app_exports.js'
169
- ) ,
187
+ ) ,
188
+ dependOn : 'vendor' ,
189
+ } ,
190
+ vendor : vendorEntry ,
191
+ vendorStyles : path . join ( __dirname , '..' , 'webpack/assets/javascripts/react_app/common/scss/vendor-core.scss' ) ,
170
192
} ;
171
193
config . output = {
172
194
path : path . join ( __dirname , '..' , 'public' , 'webpack' ) ,
@@ -179,9 +201,12 @@ const coreConfig = function() {
179
201
} ;
180
202
var plugins = config . plugins ;
181
203
204
+ plugins . push (
205
+ new MiniCssExtractPlugin ( ) ) ;
182
206
plugins . push (
183
207
new ModuleFederationPlugin ( {
184
208
name : 'foremanReact' ,
209
+ shared : shared ( false ) ,
185
210
} )
186
211
) ;
187
212
plugins . push (
@@ -191,8 +216,10 @@ const coreConfig = function() {
191
216
) ;
192
217
config . plugins = plugins ;
193
218
var rules = config . module . rules ;
219
+
194
220
rules . push ( {
195
221
test : / \. ( s a | s c | c ) s s $ / ,
222
+ exclude : / v e n d o r - c o r e / i,
196
223
use : [
197
224
{
198
225
loader : 'style-loader' ,
@@ -205,6 +232,14 @@ const coreConfig = function() {
205
232
'sass-loader' ,
206
233
] ,
207
234
} ) ;
235
+ rules . push ( {
236
+ test : / v e n d o r - c o r e / i,
237
+ use : [
238
+ MiniCssExtractPlugin . loader ,
239
+ 'css-loader' ,
240
+ 'sass-loader' ,
241
+ ] ,
242
+ } ) ;
208
243
config . module . rules = rules ;
209
244
return config ;
210
245
} ;
@@ -276,8 +311,10 @@ const pluginConfig = function(plugin) {
276
311
name : pluginName ,
277
312
filename : pluginName + '_remoteEntry.js' ,
278
313
exposes : pluginEntries ,
314
+ shared : shared ( true ) ,
279
315
} )
280
316
) ;
317
+
281
318
config . plugins = plugins ;
282
319
var rules = config . module . rules ;
283
320
rules . push ( {
0 commit comments