Skip to content

Commit

Permalink
Add new webpack watch function, and add webpack-offline-start hook
Browse files Browse the repository at this point in the history
  • Loading branch information
rvaidya committed Nov 17, 2016
1 parent 77f85f6 commit 7032e12
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Expand Up @@ -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');
Expand All @@ -18,6 +19,7 @@ class ServerlessWebpack {
this,
validate,
compile,
wpwatch,
cleanup,
run,
serve,
Expand Down Expand Up @@ -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),
};
}
}
Expand Down
23 changes: 23 additions & 0 deletions 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();
},
};

0 comments on commit 7032e12

Please sign in to comment.