Commit b1d9014a authored by Mike Greiling's avatar Mike Greiling

Merge branch 'leipert-update-webpack-dev-server' into 'master'

Update to latest webpack-dev-server

See merge request gitlab-org/gitlab!80196
parents 2964a682 8b36cbcc
...@@ -4,8 +4,8 @@ const path = require('path'); ...@@ -4,8 +4,8 @@ const path = require('path');
const { History, HistoryWithTTL } = require('./history'); const { History, HistoryWithTTL } = require('./history');
const log = require('./log'); const log = require('./log');
const onRequestEntryPoint = (app, callback) => { const onRequestEntryPoint = (callback) => {
app.use((req, res, next) => { return (req, res, next) => {
const fileName = path.basename(req.url); const fileName = path.basename(req.url);
/** /**
...@@ -20,7 +20,7 @@ const onRequestEntryPoint = (app, callback) => { ...@@ -20,7 +20,7 @@ const onRequestEntryPoint = (app, callback) => {
} }
next(); next();
}); };
}; };
/** /**
...@@ -40,7 +40,9 @@ class NoopCompiler { ...@@ -40,7 +40,9 @@ class NoopCompiler {
logStatus() {} logStatus() {}
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
setupMiddleware() {} createMiddleware() {
return null;
}
} }
/** /**
...@@ -55,8 +57,8 @@ class HistoryOnlyCompiler extends NoopCompiler { ...@@ -55,8 +57,8 @@ class HistoryOnlyCompiler extends NoopCompiler {
this.history = new History(historyFilePath); this.history = new History(historyFilePath);
} }
setupMiddleware(app) { createMiddleware() {
onRequestEntryPoint(app, (entryPoint) => { return onRequestEntryPoint((entryPoint) => {
this.history.onRequestEntryPoint(entryPoint); this.history.onRequestEntryPoint(entryPoint);
}); });
} }
...@@ -92,16 +94,16 @@ class IncrementalWebpackCompiler { ...@@ -92,16 +94,16 @@ class IncrementalWebpackCompiler {
log(`Currently compiling route entrypoints: ${this.history.size} of ${totalCount}`); log(`Currently compiling route entrypoints: ${this.history.size} of ${totalCount}`);
} }
setupMiddleware(app, server) { createMiddleware(devServer) {
onRequestEntryPoint(app, (entryPoint) => { return onRequestEntryPoint((entryPoint) => {
const wasVisitedRecently = this.history.onRequestEntryPoint(entryPoint); const wasVisitedRecently = this.history.onRequestEntryPoint(entryPoint);
if (!wasVisitedRecently) { if (!wasVisitedRecently) {
log(`Have not visited ${entryPoint} recently. Adding to compilation.`); log(`Have not visited ${entryPoint} recently. Adding to compilation.`);
setTimeout(() => { setTimeout(() => {
server.middleware.invalidate(() => { devServer.invalidate(() => {
if (server.sockets) { if (devServer.sockets) {
server.sockWrite(server.sockets, 'content-changed'); devServer.sendMessage(devServer.webSocketServer.clients, 'static-changed');
} }
}); });
}, TIMEOUT); }, TIMEOUT);
......
...@@ -38,11 +38,10 @@ const SUPPORTED_BROWSERS_HASH = crypto ...@@ -38,11 +38,10 @@ const SUPPORTED_BROWSERS_HASH = crypto
const VENDOR_DLL = process.env.WEBPACK_VENDOR_DLL && process.env.WEBPACK_VENDOR_DLL !== 'false'; const VENDOR_DLL = process.env.WEBPACK_VENDOR_DLL && process.env.WEBPACK_VENDOR_DLL !== 'false';
const CACHE_PATH = process.env.WEBPACK_CACHE_PATH || path.join(ROOT_PATH, 'tmp/cache'); const CACHE_PATH = process.env.WEBPACK_CACHE_PATH || path.join(ROOT_PATH, 'tmp/cache');
const IS_PRODUCTION = process.env.NODE_ENV === 'production'; const IS_PRODUCTION = process.env.NODE_ENV === 'production';
const IS_DEV_SERVER = process.env.WEBPACK_DEV_SERVER === 'true'; const IS_DEV_SERVER = process.env.WEBPACK_SERVE === 'true';
const DEV_SERVER_HOST = process.env.DEV_SERVER_HOST || 'localhost'; const { DEV_SERVER_HOST, DEV_SERVER_PUBLIC_ADDR } = process.env;
const DEV_SERVER_PORT = parseInt(process.env.DEV_SERVER_PORT, 10) || 3808; const DEV_SERVER_PORT = parseInt(process.env.DEV_SERVER_PORT, 10);
const { DEV_SERVER_PUBLIC_ADDR } = process.env;
const DEV_SERVER_ALLOWED_HOSTS = const DEV_SERVER_ALLOWED_HOSTS =
process.env.DEV_SERVER_ALLOWED_HOSTS && process.env.DEV_SERVER_ALLOWED_HOSTS.split(','); process.env.DEV_SERVER_ALLOWED_HOSTS && process.env.DEV_SERVER_ALLOWED_HOSTS.split(',');
const DEV_SERVER_HTTPS = process.env.DEV_SERVER_HTTPS && process.env.DEV_SERVER_HTTPS !== 'false'; const DEV_SERVER_HTTPS = process.env.DEV_SERVER_HTTPS && process.env.DEV_SERVER_HTTPS !== 'false';
...@@ -654,9 +653,6 @@ module.exports = { ...@@ -654,9 +653,6 @@ module.exports = {
}, },
}, },
// enable HMR only in webpack-dev-server
DEV_SERVER_LIVERELOAD && new webpack.HotModuleReplacementPlugin(),
// optionally generate webpack bundle analysis // optionally generate webpack bundle analysis
WEBPACK_REPORT && WEBPACK_REPORT &&
new BundleAnalyzerPlugin({ new BundleAnalyzerPlugin({
...@@ -689,19 +685,38 @@ module.exports = { ...@@ -689,19 +685,38 @@ module.exports = {
*/ */
new webpack.IgnorePlugin(/moment/, /pikaday/), new webpack.IgnorePlugin(/moment/, /pikaday/),
].filter(Boolean), ].filter(Boolean),
devServer: { devServer: {
before(app, server) { setupMiddlewares: (middlewares, devServer) => {
incrementalCompiler.setupMiddleware(app, server); if (!devServer) {
throw new Error('webpack-dev-server is not defined');
}
const incrementalCompilerMiddleware = incrementalCompiler.createMiddleware(devServer);
if (incrementalCompilerMiddleware) {
middlewares.unshift(incrementalCompilerMiddleware);
}
return middlewares;
}, },
host: DEV_SERVER_HOST, // Only print errors to CLI
port: DEV_SERVER_PORT, devMiddleware: {
public: DEV_SERVER_PUBLIC_ADDR, stats: 'errors-only',
allowedHosts: DEV_SERVER_ALLOWED_HOSTS, },
host: DEV_SERVER_HOST || 'localhost',
port: DEV_SERVER_PORT || 3808,
https: DEV_SERVER_HTTPS, https: DEV_SERVER_HTTPS,
contentBase: false,
stats: 'errors-only',
hot: DEV_SERVER_LIVERELOAD, hot: DEV_SERVER_LIVERELOAD,
inline: DEV_SERVER_LIVERELOAD, // The following settings are mainly needed for HMR support in gitpod.
// Per default only local hosts are allowed, but here we could
// allow different hosts (e.g. ['.gitpod'], all of gitpod),
// as the webpack server will run on a different subdomain than
// the rails application
...(DEV_SERVER_ALLOWED_HOSTS ? { allowedHosts: DEV_SERVER_ALLOWED_HOSTS } : {}),
client: {
...(DEV_SERVER_PUBLIC_ADDR ? { webSocketURL: DEV_SERVER_PUBLIC_ADDR } : {}),
},
}, },
devtool: NO_SOURCEMAPS ? false : devtool, devtool: NO_SOURCEMAPS ? false : devtool,
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment