You've already forked serverless-webpack
mirror of
https://github.com/encounter/serverless-webpack.git
synced 2026-03-30 11:37:58 -07:00
22a460d8b1
* Deploy package function * Listen pipe and reject pipe errors * using once instead of on * Fix babel example * - Adding babel-multiple-statically-entries example - Renaming multiple-entries-example to multiple-statically-entries * Exposing entries to lib * Adding babel-dynamically-entries examples * - Updating examples dependencies - Adding yarn to examples - Fix typescript example * Adding tests * Removed yarn lock file. yarn should use package-lock.json * Allow handlers in arbitrary paths. Use lodash and SLS functions. * Adapted unit tests * Mention new entry resolution in README * Bundle names now contain the js ending. Fixed output in examples.
163 lines
4.2 KiB
JavaScript
163 lines
4.2 KiB
JavaScript
'use strict';
|
|
|
|
const BbPromise = require('bluebird');
|
|
|
|
const validate = require('./lib/validate');
|
|
const compile = require('./lib/compile');
|
|
const copyFunctionArtifact = require('./lib/copyFunctionArtifact');
|
|
const wpwatch = require('./lib/wpwatch');
|
|
const cleanup = require('./lib/cleanup');
|
|
const run = require('./lib/run');
|
|
const serve = require('./lib/serve');
|
|
const packExternalModules = require('./lib/packExternalModules');
|
|
const lib = require('./lib');
|
|
|
|
class ServerlessWebpack {
|
|
|
|
static get lib() {
|
|
return lib;
|
|
}
|
|
|
|
constructor(serverless, options) {
|
|
this.serverless = serverless;
|
|
this.options = options;
|
|
|
|
if (
|
|
this.serverless.service
|
|
&& this.serverless.service.custom
|
|
&& this.serverless.service.custom.webpack
|
|
&& this.serverless.service.custom.webpack.endsWith('.ts')
|
|
) {
|
|
require('ts-node/register');
|
|
}
|
|
|
|
Object.assign(
|
|
this,
|
|
validate,
|
|
compile,
|
|
copyFunctionArtifact,
|
|
wpwatch,
|
|
cleanup,
|
|
run,
|
|
serve,
|
|
packExternalModules
|
|
);
|
|
|
|
this.commands = {
|
|
webpack: {
|
|
usage: 'Bundle with Webpack',
|
|
lifecycleEvents: [
|
|
'validate',
|
|
'compile',
|
|
],
|
|
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),
|
|
|
|
'before:deploy:function:packageFunction': () => BbPromise.bind(this)
|
|
.then(this.validate)
|
|
.then(this.compile)
|
|
.then(this.packExternalModules),
|
|
|
|
'after:deploy:function:packageFunction': () => BbPromise.bind(this)
|
|
.then(this.copyFunctionArtifact),
|
|
|
|
'webpack:validate': () => BbPromise.bind(this)
|
|
.then(this.validate),
|
|
|
|
'webpack:compile': () => BbPromise.bind(this)
|
|
.then(this.compile)
|
|
.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),
|
|
|
|
'before:offline:start': () => BbPromise.bind(this)
|
|
.then(this.validate)
|
|
.then(this.compile)
|
|
.then(this.wpwatch),
|
|
|
|
'before:offline:start:init': () => BbPromise.bind(this)
|
|
.then(this.validate)
|
|
.then(this.compile)
|
|
.then(this.wpwatch),
|
|
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = ServerlessWebpack;
|