@@ -4,16 +4,15 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
4
4
const MiniCssExtractPlugin = require ( "mini-css-extract-plugin" ) ;
5
5
const CopyPlugin = require ( "copy-webpack-plugin" ) ;
6
6
const nodeExternals = require ( "webpack-node-externals" ) ;
7
- const BundleAnalyzerPlugin = require ( "webpack-bundle-analyzer" )
8
- . BundleAnalyzerPlugin ;
7
+ const { BundleAnalyzerPlugin } = require ( "webpack-bundle-analyzer" ) ;
9
8
const autoprefixer = require ( "autoprefixer" ) ;
10
9
11
10
const devMode = process . env . NODE_ENV !== "production" ;
12
11
const prodMode = process . env . NODE_ENV === "production" ;
13
12
const environment = prodMode ? "production" : "development" ;
14
13
const logLevel = process . env . REACT_LOG_LEVEL || ( prodMode ? "warn" : "debug" ) ;
15
14
const reactEnvVariables = new webpack . DefinePlugin ( {
16
- [ "REACT_LOG_LEVEL" ] : JSON . stringify ( `${ logLevel } ` ) ,
15
+ [ "process.env. REACT_LOG_LEVEL" ] : JSON . stringify ( `${ logLevel } ` ) ,
17
16
} ) ;
18
17
console . log ( "****************** building client ******************" )
19
18
console . log ( `application entry : [${ path . resolve ( __dirname , "../digital-form-builder/designer/client" , "index.tsx" ) } ]\n` )
@@ -22,6 +21,32 @@ console.log(`application output : [${path.resolve(__dirname, "dist", "client")}]
22
21
console . log ( `application node_modules : [${ path . resolve ( __dirname , "../digital-form-builder/node_modules" ) } ]\n` )
23
22
console . log ( `adapter application node_modules : [${ path . resolve ( __dirname , "../digital-form-builder-adapter/node_modules" ) } \n]` )
24
23
24
+ function fixGovukImports ( url /*, prev */ ) {
25
+ const n = url . replace ( / \\ / g, "/" ) ;
26
+ const m = n . match ( / (?: ^ | \/ ) n o d e _ m o d u l e s \/ g o v u k - f r o n t e n d \/ ( .+ ) $ / ) ;
27
+ if ( m ) {
28
+ const suffix = m [ 1 ] ;
29
+ if (
30
+ suffix === "govuk/helpers/colour" ||
31
+ suffix === "govuk/helpers/_colour.scss"
32
+ ) {
33
+ return {
34
+ file : require . resolve ( "govuk-frontend/govuk/helpers/_colour.scss" ) ,
35
+ } ;
36
+ }
37
+ if ( suffix === "govuk/all.scss" || suffix === "govuk/all" ) {
38
+ return { file : require . resolve ( "govuk-frontend/govuk/all.scss" ) } ;
39
+ }
40
+ return {
41
+ file : path . join (
42
+ path . dirname ( require . resolve ( "govuk-frontend/package.json" ) ) ,
43
+ suffix
44
+ ) ,
45
+ } ;
46
+ }
47
+ return null ;
48
+ }
49
+
25
50
const client = {
26
51
target : "web" ,
27
52
mode : environment ,
@@ -37,34 +62,37 @@ const client = {
37
62
} ,
38
63
resolve : {
39
64
extensions : [ ".js" , ".jsx" , ".ts" , ".tsx" ] ,
40
- modules : [
41
- path . resolve ( __dirname , "../node_modules" )
42
- ] ,
43
- } ,
44
- node : {
45
- __dirname : false ,
65
+ modules : [ "node_modules" ] ,
66
+ fallback : {
67
+ fs : false ,
68
+ path : false ,
69
+ crypto : false ,
70
+ stream : false ,
71
+ } ,
46
72
} ,
47
73
devtool : "eval-cheap-module-source-map" ,
48
74
module : {
49
75
rules : [
76
+ {
77
+ test : / \. m ? j s $ / ,
78
+ resolve : {
79
+ fullySpecified : false ,
80
+ } ,
81
+ } ,
50
82
{
51
83
test : / \. ( j s | j s x | t s x | t s ) $ / ,
52
- exclude : [
53
- {
54
- test : / n o d e _ m o d u l e s / ,
55
- exclude : / p i n o / ,
56
- } ,
57
- ] ,
58
- loader : "babel-loader" ,
84
+ exclude : ( modulePath ) =>
85
+ / n o d e _ m o d u l e s / . test ( modulePath ) && ! / n o d e _ m o d u l e s [ \\ / ] ( p i n o ) / . test ( modulePath ) ,
86
+ use : {
87
+ loader : "babel-loader" ,
88
+ } ,
59
89
} ,
60
90
{
61
91
test : / \. ( s a | s c | c ) s s $ / ,
62
92
use : [
63
93
{
64
94
loader : MiniCssExtractPlugin . loader ,
65
95
options : {
66
- hmr : devMode ,
67
- reloadAll : true ,
68
96
publicPath : "../../" ,
69
97
} ,
70
98
} ,
@@ -74,12 +102,19 @@ const client = {
74
102
} ,
75
103
{
76
104
loader : "postcss-loader" ,
105
+ options : {
106
+ postcssOptions : {
107
+ plugins : [ autoprefixer ( ) ] ,
108
+ } ,
109
+ } ,
77
110
} ,
78
111
{
79
112
loader : "sass-loader" ,
80
113
options : {
114
+ implementation : require ( "sass" ) ,
81
115
sassOptions : {
82
116
outputStyle : "expanded" ,
117
+ importer : fixGovukImports ,
83
118
} ,
84
119
} ,
85
120
} ,
@@ -111,12 +146,8 @@ const client = {
111
146
hash : prodMode ,
112
147
} ) ,
113
148
new MiniCssExtractPlugin ( {
114
- filename : devMode
115
- ? "assets/css/[name].css"
116
- : "assets/css/[name].[hash].css" ,
117
- chunkFilename : devMode
118
- ? "assets/css/[id].css"
119
- : "assets/css/[id].[hash].css" ,
149
+ filename : devMode ? "assets/css/[name].css" : "assets/css/[name].[contenthash].css" ,
150
+ chunkFilename : devMode ? "assets/css/[id].css" : "assets/css/[id].[contenthash].css" ,
120
151
} ) ,
121
152
new CopyPlugin ( {
122
153
patterns : [
@@ -145,9 +176,7 @@ const server = {
145
176
} ,
146
177
resolve : {
147
178
extensions : [ ".js" , ".jsx" , ".ts" , ".tsx" ] ,
148
- modules : [
149
- path . resolve ( __dirname , "../node_modules" )
150
- ] ,
179
+ modules : [ "node_modules" ] ,
151
180
} ,
152
181
node : {
153
182
__dirname : false ,
@@ -160,17 +189,15 @@ const server = {
160
189
{
161
190
test : / \. ( j s | j s x | t s x | t s ) $ / ,
162
191
exclude : / n o d e _ m o d u l e s / ,
163
- loader : "babel-loader" ,
192
+ use : {
193
+ loader : "babel-loader" ,
194
+ } ,
164
195
} ,
165
196
] ,
166
197
} ,
167
198
externals : [
168
- nodeExternals ( {
169
- modulesDir : path . resolve ( __dirname , "../digital-form-builder/node_modules" ) ,
170
- } ) ,
171
- nodeExternals ( {
172
- modulesDir : path . resolve ( __dirname , "../digital-form-builder-adapter/node_modules" ) ,
173
- } ) ,
199
+ nodeExternals ( ) ,
200
+ { fsevents : "commonjs fsevents" } ,
174
201
] ,
175
202
} ;
176
203
0 commit comments