From 56315a328c483b4a94fd3d3d3db7d74c718495be Mon Sep 17 00:00:00 2001 From: dmbch Date: Thu, 25 Jan 2018 22:43:31 +0100 Subject: [PATCH] refactor(build): get rid of WDS, use Express BREAKING CHANGE: Since we got rid of webpack dev server, its config is no longer supported. All existing hops features (including SSL) are still supported, though. --- packages/build/build.js | 13 ++---------- packages/build/package.json | 4 +++- packages/build/server.js | 42 +++++++++++++++++++------------------ 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/packages/build/build.js b/packages/build/build.js index 2bac6646ee..a5d8820363 100644 --- a/packages/build/build.js +++ b/packages/build/build.js @@ -1,7 +1,6 @@ 'use strict'; var webpack = require('webpack'); -var merge = require('webpack-merge'); var hopsConfig = require('hops-config'); var hopsBuildConfig = require('hops-build-config'); @@ -9,16 +8,8 @@ var hopsBuildConfig = require('hops-build-config'); var generate = require('./lib/generate'); var cleanup = require('./lib/cleanup'); -var mergeWithPlugins = merge.strategy({ plugins: 'append' }); - -function injectProgressPlugin(webpackConfig) { - return mergeWithPlugins(webpackConfig, { - plugins: [new webpack.ProgressPlugin()], - }); -} - -var buildConfig = injectProgressPlugin(require(hopsBuildConfig.buildConfig)); -var nodeConfig = injectProgressPlugin(require(hopsBuildConfig.nodeConfig)); +var buildConfig = require(hopsBuildConfig.buildConfig); +var nodeConfig = require(hopsBuildConfig.nodeConfig); function defaultCallback(error, stats) { if (error) { diff --git a/packages/build/package.json b/packages/build/package.json index 2bc3ba57d1..f497a90817 100644 --- a/packages/build/package.json +++ b/packages/build/package.json @@ -25,6 +25,7 @@ }, "dependencies": { "directory-index": "^0.1.0", + "express": "^4.16.0", "filesize": "^3.5.11", "hops-build-config": "10.0.1", "hops-config": "10.0.1", @@ -34,7 +35,8 @@ "mkdirp": "^0.5.1", "rimraf": "^2.6.2", "webpack": "^3.6.0", - "webpack-dev-server": "^2.10.0", + "webpack-dev-middleware": "^2.0.4", + "webpack-hot-middleware": "^2.21.0", "webpack-merge": "^4.1.1" } } diff --git a/packages/build/server.js b/packages/build/server.js index c4e720fd52..de6ff589c3 100644 --- a/packages/build/server.js +++ b/packages/build/server.js @@ -1,7 +1,10 @@ 'use strict'; +var express = require('express'); + var webpack = require('webpack'); -var WebpackServer = require('webpack-dev-server'); +var webpackDevMiddleware = require('webpack-dev-middleware'); +var webpackHotMiddleware = require('webpack-hot-middleware'); var hopsConfig = require('hops-config'); var hopsBuildConfig = require('hops-build-config'); @@ -16,26 +19,25 @@ process.on('unhandledRejection', function(error) { function runDevelop(options, callback) { var config = require(hopsBuildConfig.developConfig); - var watchOptions = config.devServer.watchOptions || config.watchOptions; - var app = new WebpackServer( - webpack(config), - Object.assign( - {}, - { - after: function(app) { - app.use(utils.rewritePath); - utils.bootstrap(app, hopsConfig); - utils.registerMiddleware( - app, - createMiddleware(require(hopsBuildConfig.nodeConfig), watchOptions) - ); - utils.teardown(app, hopsConfig); - }, - watchOptions: watchOptions, - }, - config.devServer - ) + var compiler = webpack(config); + var app = express(); + app.use( + webpackDevMiddleware(compiler, { + noInfo: true, + logLevel: 'warn', + publicPath: config.output.publicPath, + watchOptions: config.watchOptions, + }) + ); + app.use(webpackHotMiddleware(compiler)); + app.use(utils.rewritePath); + app.use(express.static(hopsConfig.buildDir, { redirect: false })); + utils.bootstrap(app, hopsConfig); + utils.registerMiddleware( + app, + createMiddleware(require(hopsBuildConfig.nodeConfig), config.watchOptions) ); + utils.teardown(app, hopsConfig); utils.run(app, callback); }