Skip to content

Commit fada0d8

Browse files
authored
Merge pull request #11994 from archesproject/11993-cbyrd-fix-webpack-deveserver-memory-leak
fixes webpack dev server memory leak #11993
2 parents 5356812 + b2b1e12 commit fada0d8

File tree

2 files changed

+66
-34
lines changed

2 files changed

+66
-34
lines changed

arches/install/arches-templates/webpack/webpack.config.dev.js

+33-17
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,66 @@ const StylelintPlugin = require('stylelint-webpack-plugin');
77

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

10+
class WatchArchesUrlsPlugin {
11+
constructor(watchPath) {
12+
this.watchPath = watchPath;
13+
}
14+
15+
apply(compiler) {
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);
25+
}
26+
});
27+
}
28+
}
29+
1030
module.exports = () => {
11-
return new Promise((resolve, _reject) => {
31+
return new Promise((resolve) => {
1232
commonWebpackConfigPromise().then(commonWebpackConfig => {
1333
resolve(merge(commonWebpackConfig, {
1434
mode: 'development',
35+
cache: {
36+
type: 'filesystem',
37+
buildDependencies: {
38+
config: [__filename],
39+
},
40+
},
1541
devtool: 'inline-source-map',
42+
target: 'web',
1643
devServer: {
1744
historyApiFallback: true,
18-
client: {
19-
overlay: false,
20-
},
45+
client: { overlay: false },
2146
hot: true,
2247
host: '0.0.0.0',
48+
port: commonWebpackConfig.WEBPACK_DEVELOPMENT_SERVER_PORT,
2349
devMiddleware: {
2450
index: true,
2551
writeToDisk: true,
2652
},
27-
port: commonWebpackConfig.WEBPACK_DEVELOPMENT_SERVER_PORT,
2853
},
2954
watchOptions: {
3055
ignored: '**/node_modules',
3156
},
3257
stats: {
33-
modules: false
58+
modules: false,
3459
},
35-
target: 'web',
3660
plugins: [
3761
new Webpack.DefinePlugin({
3862
'process.env.NODE_ENV': JSON.stringify('development'),
3963
}),
4064
new StylelintPlugin({
4165
files: Path.join('src', '**/*.s?(a|c)ss'),
4266
}),
43-
{
44-
apply: (compiler) => {
45-
compiler.hooks.afterCompile.tap('WatchArchesUrlsPlugin', (compilation) => {
46-
compilation.fileDependencies.add(
47-
Path.resolve(__dirname, APP_ROOT, '..', 'frontend_configuration', 'urls.json')
48-
);
49-
});
50-
},
51-
},
67+
new WatchArchesUrlsPlugin(Path.join(__dirname, "..", "frontend_configuration", 'urls.json')),
5268
],
5369
}));
5470
});
5571
});
56-
};
72+
};

webpack/webpack.config.dev.js

+33-17
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,66 @@ const StylelintPlugin = require('stylelint-webpack-plugin');
77

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

10+
class WatchArchesUrlsPlugin {
11+
constructor(watchPath) {
12+
this.watchPath = watchPath;
13+
}
14+
15+
apply(compiler) {
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);
25+
}
26+
});
27+
}
28+
}
29+
1030
module.exports = () => {
11-
return new Promise((resolve, _reject) => {
31+
return new Promise((resolve) => {
1232
commonWebpackConfigPromise().then(commonWebpackConfig => {
1333
resolve(merge(commonWebpackConfig, {
1434
mode: 'development',
35+
cache: {
36+
type: 'filesystem',
37+
buildDependencies: {
38+
config: [__filename],
39+
},
40+
},
1541
devtool: 'inline-source-map',
42+
target: 'web',
1643
devServer: {
1744
historyApiFallback: true,
18-
client: {
19-
overlay: false,
20-
},
45+
client: { overlay: false },
2146
hot: true,
2247
host: '0.0.0.0',
48+
port: commonWebpackConfig.WEBPACK_DEVELOPMENT_SERVER_PORT,
2349
devMiddleware: {
2450
index: true,
2551
writeToDisk: true,
2652
},
27-
port: commonWebpackConfig.WEBPACK_DEVELOPMENT_SERVER_PORT,
2853
},
2954
watchOptions: {
3055
ignored: '**/node_modules',
3156
},
3257
stats: {
33-
modules: false
58+
modules: false,
3459
},
35-
target: 'web',
3660
plugins: [
3761
new Webpack.DefinePlugin({
3862
'process.env.NODE_ENV': JSON.stringify('development'),
3963
}),
4064
new StylelintPlugin({
4165
files: Path.join('src', '**/*.s?(a|c)ss'),
4266
}),
43-
{
44-
apply: (compiler) => {
45-
compiler.hooks.afterCompile.tap('WatchArchesUrlsPlugin', (compilation) => {
46-
compilation.fileDependencies.add(
47-
Path.resolve(__dirname, APP_ROOT, '..', 'frontend_configuration', 'urls.json')
48-
);
49-
});
50-
},
51-
},
67+
new WatchArchesUrlsPlugin(Path.join(__dirname, "..", "frontend_configuration", 'urls.json')),
5268
],
5369
}));
5470
});
5571
});
56-
};
72+
};

0 commit comments

Comments
 (0)