Skip to content

Commit

Permalink
refactor(build): get rid of WDS, use Express
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dmbch committed Feb 14, 2018
1 parent a489f14 commit 56315a3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
13 changes: 2 additions & 11 deletions packages/build/build.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
'use strict';

var webpack = require('webpack');
var merge = require('webpack-merge');

var hopsConfig = require('hops-config');
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) {
Expand Down
4 changes: 3 additions & 1 deletion packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
42 changes: 22 additions & 20 deletions packages/build/server.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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);
}

Expand Down

0 comments on commit 56315a3

Please sign in to comment.