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(); + }, +};