You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.3 KiB
127 lines
3.3 KiB
'use strict';
|
|
|
|
const BbPromise = require('bluebird');
|
|
|
|
const validate = require('./lib/validate');
|
|
const compile = require('./lib/compile');
|
|
const cleanup = require('./lib/cleanup');
|
|
const run = require('./lib/run');
|
|
const serve = require('./lib/serve');
|
|
const packExternalModules = require('./lib/packExternalModules')
|
|
|
|
class ServerlessWebpack {
|
|
constructor(serverless, options) {
|
|
this.serverless = serverless;
|
|
this.options = options;
|
|
|
|
Object.assign(
|
|
this,
|
|
validate,
|
|
compile,
|
|
cleanup,
|
|
run,
|
|
serve,
|
|
packExternalModules
|
|
);
|
|
|
|
this.commands = {
|
|
webpack: {
|
|
usage: 'Bundle with Webpack',
|
|
lifecycleEvents: [
|
|
'validate',
|
|
'compile',
|
|
'packExternalModules',
|
|
],
|
|
options: {
|
|
out: {
|
|
usage: 'Path to output directory',
|
|
shortcut: 'o',
|
|
},
|
|
},
|
|
commands: {
|
|
invoke: {
|
|
usage: 'Run a function locally from the webpack output bundle',
|
|
lifecycleEvents: [
|
|
'invoke',
|
|
],
|
|
options: {
|
|
function: {
|
|
usage: 'Name of the function',
|
|
shortcut: 'f',
|
|
required: true,
|
|
},
|
|
path: {
|
|
usage: 'Path to JSON file holding input data',
|
|
shortcut: 'p',
|
|
},
|
|
},
|
|
},
|
|
watch: {
|
|
usage: 'Run a function from the webpack output bundle every time the source is changed',
|
|
lifecycleEvents: [
|
|
'watch',
|
|
],
|
|
options: {
|
|
function: {
|
|
usage: 'Name of the function',
|
|
shortcut: 'f',
|
|
required: true,
|
|
},
|
|
path: {
|
|
usage: 'Path to JSON file holding input data',
|
|
shortcut: 'p',
|
|
},
|
|
},
|
|
},
|
|
serve: {
|
|
usage: 'Simulate the API Gateway and serves lambdas locally',
|
|
lifecycleEvents: [
|
|
'serve',
|
|
],
|
|
options: {
|
|
port: {
|
|
usage: 'The local server port',
|
|
shortcut: 'p',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
this.hooks = {
|
|
'before:deploy:createDeploymentArtifacts': () => BbPromise.bind(this)
|
|
.then(this.validate)
|
|
.then(this.compile)
|
|
.then(this.packExternalModules),
|
|
|
|
'after:deploy:createDeploymentArtifacts': () => BbPromise.bind(this)
|
|
.then(this.cleanup),
|
|
|
|
'webpack:validate': () => BbPromise.bind(this)
|
|
.then(this.validate),
|
|
|
|
'webpack:compile': () => BbPromise.bind(this)
|
|
.then(this.compile),
|
|
|
|
'webpack:packExternalModules': () => BbPromise.bind(this)
|
|
.then(this.packExternalModules),
|
|
|
|
'webpack:invoke:invoke': () => BbPromise.bind(this)
|
|
.then(this.validate)
|
|
.then(this.compile)
|
|
.then(this.run)
|
|
.then(out => this.serverless.cli.consoleLog(out)),
|
|
|
|
'webpack:watch:watch': () => BbPromise.bind(this)
|
|
.then(this.validate)
|
|
.then(this.watch),
|
|
|
|
'webpack:serve:serve': () => BbPromise.bind(this)
|
|
.then(this.validate)
|
|
.then(this.serve),
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = ServerlessWebpack;
|
|
|