1
1
/* eslint-disable */
2
- const fs = require ( 'fs' ) ;
2
+
3
3
const Path = require ( 'path' ) ;
4
4
const Webpack = require ( 'webpack' ) ;
5
5
const { merge } = require ( 'webpack-merge' ) ;
6
6
const StylelintPlugin = require ( 'stylelint-webpack-plugin' ) ;
7
7
8
8
const commonWebpackConfigPromise = require ( './webpack.common.js' ) ;
9
9
10
- class WatchFilePlugin {
11
- constructor ( filePath ) {
12
- this . filePath = filePath ;
13
- this . watcher = null ;
10
+ class WatchArchesUrlsPlugin {
11
+ constructor ( watchPath ) {
12
+ this . watchPath = watchPath ;
14
13
}
15
14
16
15
apply ( compiler ) {
17
- compiler . hooks . afterEnvironment . tap ( 'WatchFilePlugin' , ( ) => {
18
- if ( this . watcher ) return ;
19
-
20
- this . watcher = fs . watch ( this . filePath , ( eventType ) => {
21
- if ( eventType === 'change' && compiler . watching ) {
22
- compiler . watching . invalidate ( ) ;
23
- }
24
- } ) ;
25
- } ) ;
26
-
27
- compiler . hooks . watchClose . tap ( 'WatchFilePlugin' , ( ) => {
28
- if ( this . watcher ) {
29
- this . watcher . close ( ) ;
30
- this . watcher = null ;
16
+ compiler . hooks . afterCompile . tap ( 'WatchArchesUrlsPlugin' , ( compilation ) => {
17
+ if (
18
+ compilation . fileDependencies &&
19
+ typeof compilation . fileDependencies . add === 'function'
20
+ ) {
21
+ compilation . fileDependencies . add ( this . watchPath ) ;
22
+ }
23
+ else if ( Array . isArray ( compilation . fileDependencies ) ) {
24
+ compilation . fileDependencies . push ( this . watchPath ) ;
31
25
}
32
26
} ) ;
33
27
}
34
28
}
35
29
36
-
37
30
module . exports = ( ) => {
38
- return new Promise ( ( resolve , _reject ) => {
31
+ return new Promise ( ( resolve ) => {
39
32
commonWebpackConfigPromise ( ) . then ( commonWebpackConfig => {
40
33
resolve ( merge ( commonWebpackConfig , {
41
34
mode : 'development' ,
@@ -46,38 +39,34 @@ module.exports = () => {
46
39
} ,
47
40
} ,
48
41
devtool : 'inline-source-map' ,
42
+ target : 'web' ,
49
43
devServer : {
50
44
historyApiFallback : true ,
51
- client : {
52
- overlay : false ,
53
- } ,
45
+ client : { overlay : false } ,
54
46
hot : true ,
55
47
host : '0.0.0.0' ,
48
+ port : commonWebpackConfig . WEBPACK_DEVELOPMENT_SERVER_PORT ,
56
49
devMiddleware : {
57
50
index : true ,
58
51
writeToDisk : true ,
59
52
} ,
60
- port : commonWebpackConfig . WEBPACK_DEVELOPMENT_SERVER_PORT ,
61
53
} ,
62
54
watchOptions : {
63
55
ignored : '**/node_modules' ,
64
56
} ,
65
57
stats : {
66
- modules : false
58
+ modules : false ,
67
59
} ,
68
- target : 'web' ,
69
60
plugins : [
70
61
new Webpack . DefinePlugin ( {
71
62
'process.env.NODE_ENV' : JSON . stringify ( 'development' ) ,
72
63
} ) ,
73
64
new StylelintPlugin ( {
74
65
files : Path . join ( 'src' , '**/*.s?(a|c)ss' ) ,
75
66
} ) ,
76
- new WatchFilePlugin (
77
- Path . join ( __dirname , ".." , "frontend_configuration" , 'urls.json' )
78
- ) ,
67
+ new WatchArchesUrlsPlugin ( Path . join ( __dirname , ".." , "frontend_configuration" , 'urls.json' ) ) ,
79
68
] ,
80
69
} ) ) ;
81
70
} ) ;
82
71
} ) ;
83
- } ;
72
+ } ;
0 commit comments