Nicola Peduzzi
8 years ago
committed by
GitHub
10 changed files with 151 additions and 2 deletions
@ -0,0 +1,5 @@ |
|||
{ |
|||
"key3": "value3", |
|||
"key2": "value2", |
|||
"key1": "value1" |
|||
} |
@ -0,0 +1,8 @@ |
|||
'use strict'; |
|||
|
|||
var AWS = require('aws-sdk'); |
|||
var fbgraph = require('fbgraph'); |
|||
|
|||
module.exports.hello = function (event, context, cb) { |
|||
cb(null, { message: 'hello fb & aws', event }); |
|||
} |
@ -0,0 +1,19 @@ |
|||
{ |
|||
"name": "serverless-include-external-npm-package", |
|||
"version": "1.0.0", |
|||
"description": "Serverless webpack example", |
|||
"main": "handler.js", |
|||
"scripts": { |
|||
"test": "echo \"Error: no test specified\" && exit 1" |
|||
}, |
|||
"author": "Tony Yuen <colsy2@gmail.com>", |
|||
"license": "MIT", |
|||
"devDependencies": { |
|||
"serverless-webpack": "^1.0.0-beta.2", |
|||
"webpack": "^1.13.1" |
|||
}, |
|||
"dependencies": { |
|||
"aws-sdk": "^2.5.3", |
|||
"fbgraph": "^1.3.0" |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
# This is the Serverless Environment File |
|||
# |
|||
# It contains listing of your stages and their regions |
|||
# It also manages serverless variables at 3 levels: |
|||
# - common variables: variables that apply to all stages/regions |
|||
# - stage variables: variables that apply to a specific stage |
|||
# - region variables: variables that apply to a specific region |
|||
|
|||
vars: |
|||
stages: |
|||
dev: |
|||
vars: |
|||
regions: |
|||
us-east-1: |
|||
vars: |
@ -0,0 +1,21 @@ |
|||
service: serverless-webpack-multiple-entries-example |
|||
|
|||
# Add the serverless-webpack plugin |
|||
plugins: |
|||
- serverless-webpack |
|||
|
|||
provider: |
|||
name: aws |
|||
runtime: nodejs4.3 |
|||
|
|||
custom: |
|||
webpackIncludeModules: # modules to be included in distribution |
|||
- fbgraph |
|||
|
|||
functions: |
|||
first: |
|||
handler: handler.hello |
|||
events: |
|||
- http: |
|||
method: GET |
|||
path: first |
@ -0,0 +1,7 @@ |
|||
var path = require('path'); |
|||
|
|||
module.exports = { |
|||
entry: './handler.js', |
|||
target: 'node', |
|||
externals: ["fbgraph", "aws-sdk"] // modules to be excluded from bundled file
|
|||
}; |
@ -0,0 +1,42 @@ |
|||
'use strict'; |
|||
|
|||
const BbPromise = require('bluebird'); |
|||
const fs = require('fs'); |
|||
const path = require('path'); |
|||
const npm = require('npm-programmatic'); |
|||
|
|||
module.exports = { |
|||
packExternalModules() { |
|||
|
|||
const includes = ( |
|||
this.serverless.service.custom && |
|||
this.serverless.service.custom.webpackIncludeModules |
|||
); |
|||
|
|||
return BbPromise.resolve().then(() => { |
|||
if (!includes || includes.length === 0) { |
|||
return; |
|||
} |
|||
|
|||
this.serverless.cli.log('Packing external modules: ' + includes.join(",")); |
|||
|
|||
const tmpPackageJson = path.join(this.serverless.config.servicePath, 'package.json'); |
|||
|
|||
// create a temp package.json in dist directory so that we can install the dependencies later.
|
|||
fs.writeFileSync(tmpPackageJson, "{}"); |
|||
|
|||
return new BbPromise((resolve, reject) => { |
|||
npm.install(includes, { |
|||
cwd: this.serverless.config.servicePath, |
|||
save: false |
|||
}).then(() => { |
|||
fs.unlink(tmpPackageJson); |
|||
resolve() |
|||
}).catch(e => { |
|||
fs.unlink(tmpPackageJson); |
|||
reject(e); |
|||
}) |
|||
}) |
|||
}) |
|||
}, |
|||
}; |
Loading…
Reference in new issue