Skip to content

Commit

Permalink
(#9) fix server startup and teardown in normal compile mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jpommerening committed Sep 13, 2017
1 parent 9336816 commit 400d18e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Last Changes

- [#9](https://github.com/aixigo/pdfreactor-loader/issues/9): Fix server startup and teardown inconsistencies


## v0.3.0

Expand Down
12 changes: 11 additions & 1 deletion plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = function( options ) {
apply( compiler ) {
const context = ( options && options.context ) || compiler.context;
const middleware = [];
let watching = false;

if( Array.isArray( options.middleware ) ) {
middleware.push.apply( middleware, options.middleware );
Expand Down Expand Up @@ -49,6 +50,8 @@ module.exports = function( options ) {
middleware.forEach( server.use );
} );
compiler.plugin( 'watch-run', ( watcher, callback ) => {
watching = true;

server.listen( err => {
const baseUrl = `http://localhost:${server.address().port}/`;
if( !err ) {
Expand All @@ -63,7 +66,14 @@ module.exports = function( options ) {
callback();
} );
compiler.plugin( 'before-run', ( compiler, callback ) => {
server.listen( callback );
if( !watching ) {
server.listen( callback );
}
} );
compiler.plugin( 'done', stats => {
if( !watching ) {
server.close();
}
} );
compiler.plugin( 'compilation', compilation => {
compilation.plugin( 'normal-module-loader', ( loaderContext, module ) => {
Expand Down

0 comments on commit 400d18e

Please sign in to comment.