Skip to content

Commit b2b1e12

Browse files
committed
fix #11993
1 parent 0d77419 commit b2b1e12

File tree

2 files changed

+40
-62
lines changed

2 files changed

+40
-62
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,34 @@
11
/* eslint-disable */
2-
const fs = require('fs');
2+
33
const Path = require('path');
44
const Webpack = require('webpack');
55
const { merge } = require('webpack-merge');
66
const StylelintPlugin = require('stylelint-webpack-plugin');
77

88
const commonWebpackConfigPromise = require('./webpack.common.js');
99

10-
class WatchFilePlugin {
11-
constructor(filePath) {
12-
this.filePath = filePath;
13-
this.watcher = null;
10+
class WatchArchesUrlsPlugin {
11+
constructor(watchPath) {
12+
this.watchPath = watchPath;
1413
}
1514

1615
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);
3125
}
3226
});
3327
}
3428
}
3529

36-
3730
module.exports = () => {
38-
return new Promise((resolve, _reject) => {
31+
return new Promise((resolve) => {
3932
commonWebpackConfigPromise().then(commonWebpackConfig => {
4033
resolve(merge(commonWebpackConfig, {
4134
mode: 'development',
@@ -46,38 +39,34 @@ module.exports = () => {
4639
},
4740
},
4841
devtool: 'inline-source-map',
42+
target: 'web',
4943
devServer: {
5044
historyApiFallback: true,
51-
client: {
52-
overlay: false,
53-
},
45+
client: { overlay: false },
5446
hot: true,
5547
host: '0.0.0.0',
48+
port: commonWebpackConfig.WEBPACK_DEVELOPMENT_SERVER_PORT,
5649
devMiddleware: {
5750
index: true,
5851
writeToDisk: true,
5952
},
60-
port: commonWebpackConfig.WEBPACK_DEVELOPMENT_SERVER_PORT,
6153
},
6254
watchOptions: {
6355
ignored: '**/node_modules',
6456
},
6557
stats: {
66-
modules: false
58+
modules: false,
6759
},
68-
target: 'web',
6960
plugins: [
7061
new Webpack.DefinePlugin({
7162
'process.env.NODE_ENV': JSON.stringify('development'),
7263
}),
7364
new StylelintPlugin({
7465
files: Path.join('src', '**/*.s?(a|c)ss'),
7566
}),
76-
new WatchFilePlugin(
77-
Path.join(__dirname, "..", "frontend_configuration", 'urls.json')
78-
),
67+
new WatchArchesUrlsPlugin(Path.join(__dirname, "..", "frontend_configuration", 'urls.json')),
7968
],
8069
}));
8170
});
8271
});
83-
};
72+
};

webpack/webpack.config.dev.js

+20-31
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,34 @@
11
/* eslint-disable */
2-
const fs = require('fs');
2+
33
const Path = require('path');
44
const Webpack = require('webpack');
55
const { merge } = require('webpack-merge');
66
const StylelintPlugin = require('stylelint-webpack-plugin');
77

88
const commonWebpackConfigPromise = require('./webpack.common.js');
99

10-
class WatchFilePlugin {
11-
constructor(filePath) {
12-
this.filePath = filePath;
13-
this.watcher = null;
10+
class WatchArchesUrlsPlugin {
11+
constructor(watchPath) {
12+
this.watchPath = watchPath;
1413
}
1514

1615
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);
3125
}
3226
});
3327
}
3428
}
3529

36-
3730
module.exports = () => {
38-
return new Promise((resolve, _reject) => {
31+
return new Promise((resolve) => {
3932
commonWebpackConfigPromise().then(commonWebpackConfig => {
4033
resolve(merge(commonWebpackConfig, {
4134
mode: 'development',
@@ -46,38 +39,34 @@ module.exports = () => {
4639
},
4740
},
4841
devtool: 'inline-source-map',
42+
target: 'web',
4943
devServer: {
5044
historyApiFallback: true,
51-
client: {
52-
overlay: false,
53-
},
45+
client: { overlay: false },
5446
hot: true,
5547
host: '0.0.0.0',
48+
port: commonWebpackConfig.WEBPACK_DEVELOPMENT_SERVER_PORT,
5649
devMiddleware: {
5750
index: true,
5851
writeToDisk: true,
5952
},
60-
port: commonWebpackConfig.WEBPACK_DEVELOPMENT_SERVER_PORT,
6153
},
6254
watchOptions: {
6355
ignored: '**/node_modules',
6456
},
6557
stats: {
66-
modules: false
58+
modules: false,
6759
},
68-
target: 'web',
6960
plugins: [
7061
new Webpack.DefinePlugin({
7162
'process.env.NODE_ENV': JSON.stringify('development'),
7263
}),
7364
new StylelintPlugin({
7465
files: Path.join('src', '**/*.s?(a|c)ss'),
7566
}),
76-
new WatchFilePlugin(
77-
Path.join(__dirname, "..", "frontend_configuration", 'urls.json')
78-
),
67+
new WatchArchesUrlsPlugin(Path.join(__dirname, "..", "frontend_configuration", 'urls.json')),
7968
],
8069
}));
8170
});
8271
});
83-
};
72+
};

0 commit comments

Comments
 (0)