Last active
July 16, 2019 07:09
-
-
Save henrikbjorn/d2eef51257a3937c5cdbd42836eeb012 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const fs = require('fs') | |
const webpack = require('webpack') | |
const CloudFormation = require('yaml-cfn') | |
// Extract the AWS::Serverless::Function Resources as they | |
// are the entires we need to compile. | |
const { Resources } = CloudFormation.yamlParse(fs.readFileSync('template.yml')) | |
const entries = Object.values(Resources) | |
.filter(resource => resource.Type == 'AWS::Serverless::Function') | |
.filter(resource => resource.Properties.Runtime.startsWith('nodejs')) | |
.map(resource => { | |
const file = resource.Properties.Handler.split('.')[0] | |
const prefix = resource.Properties.CodeUri.substr(9) | |
return { | |
name: `${prefix}/${file}`, | |
entry: `${prefix}/${file}.ts`, | |
} | |
}) | |
.reduce((accumulator, resource) => { | |
const { name, entry } = resource | |
return Object.assign(accumulator, { | |
[name]: path.resolve(entry), | |
}) | |
}, {}) | |
console.log(entries) | |
module.exports = { | |
entry: entries, | |
resolve: { | |
extensions: ['.js', '.ts'] | |
}, | |
target: 'node', | |
devtool: false, | |
mode: process.env.NODE_ENV, | |
output: { | |
path: path.resolve('.webpack'), | |
filename: '[name].js', | |
libraryTarget: 'commonjs' | |
}, | |
externals: ['aws-sdk'], | |
stats: 'errors-warnings', | |
plugins: [ | |
new webpack.EnvironmentPlugin({ | |
NODE_ENV: 'development', | |
}), | |
], | |
optimization: { | |
minimize: false, | |
}, | |
performance: { | |
hints: false, | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.ts(x?)$/, | |
use: [ | |
{ | |
loader: 'ts-loader' | |
} | |
], | |
} | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment