You've already forked serverless-webpack
mirror of
https://github.com/encounter/serverless-webpack.git
synced 2026-03-30 11:37:58 -07:00
a1f708c186
Small README change Raise coverage again Added unit tests Added serverless run to README Added watch unit tests with handler function. Support --watch for run command Package external modules for run Hook run:run, set service packaging and change to compiled directory
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
const BbPromise = require('bluebird');
|
|
const webpack = require('webpack');
|
|
|
|
module.exports = {
|
|
watch(command) {
|
|
const functionName = this.options.function;
|
|
if (functionName) {
|
|
this.serverless.cli.log(`Watch function ${functionName}...`);
|
|
} else {
|
|
this.serverless.cli.log('Watch service...');
|
|
}
|
|
|
|
const compiler = webpack(this.webpackConfig);
|
|
const watchOptions = {};
|
|
const usePolling = this.options['webpack-use-polling'];
|
|
if (usePolling) {
|
|
watchOptions.poll = _.isInteger(usePolling) ? usePolling : 3000;
|
|
this.serverless.cli.log(`Enabled polling (${watchOptions.poll} ms)`);
|
|
}
|
|
|
|
compiler.watch(watchOptions, (err /*, stats */) => {
|
|
if (err) {
|
|
throw err;
|
|
}
|
|
|
|
BbPromise.try(() => { // eslint-disable-line promise/catch-or-return, promise/no-promise-in-callback
|
|
if (this.originalServicePath) {
|
|
process.chdir(this.originalServicePath);
|
|
this.serverless.config.servicePath = this.originalServicePath;
|
|
}
|
|
|
|
if (!this.isWatching) {
|
|
this.isWatching = true;
|
|
return BbPromise.resolve();
|
|
}
|
|
|
|
this.serverless.cli.log('Sources changed.');
|
|
if (_.isFunction(command)) {
|
|
return command();
|
|
}
|
|
this.options.verbose && this.serverless.cli.log(`Invoke ${command}`);
|
|
return this.serverless.pluginManager.spawn(command);
|
|
})
|
|
.then(() => this.serverless.cli.log('Waiting for changes ...'));
|
|
});
|
|
},
|
|
};
|