From 7032e12f38fe5d4f5ccd65cbb567aa7377a3e26a Mon Sep 17 00:00:00 2001 From: rahul Date: Thu, 17 Nov 2016 14:41:13 -0800 Subject: [PATCH] Add new webpack watch function, and add webpack-offline-start hook --- index.js | 6 ++++++ lib/wpwatch.js | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 lib/wpwatch.js diff --git a/index.js b/index.js index bdb70fd..240f2eb 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ const BbPromise = require('bluebird'); const validate = require('./lib/validate'); const compile = require('./lib/compile'); +const wpwatch = require('./lib/wpwatch'); const cleanup = require('./lib/cleanup'); const run = require('./lib/run'); const serve = require('./lib/serve'); @@ -18,6 +19,7 @@ class ServerlessWebpack { this, validate, compile, + wpwatch, cleanup, run, serve, @@ -117,6 +119,10 @@ class ServerlessWebpack { 'webpack:serve:serve': () => BbPromise.bind(this) .then(this.validate) .then(this.serve), + + 'before:offline:start': () => BbPromise.bind(this) + .then(this.validate) + .then(this.wpwatch), }; } } diff --git a/lib/wpwatch.js b/lib/wpwatch.js new file mode 100644 index 0000000..e4e02fc --- /dev/null +++ b/lib/wpwatch.js @@ -0,0 +1,23 @@ +'use strict'; + +const BbPromise = require('bluebird'); +const webpack = require('webpack'); + +module.exports = { + wpwatch() { + this.serverless.cli.log('Watching with Webpack...'); + + const compiler = webpack(this.webpackConfig); + compiler.watch({}, (err, stats) => { + if (err) { + throw err; + } + + if (stats) { + console.log("Webpack rebuilt"); + } + }); + + return BbPromise.resolve(); + }, +};