Skip to content

Instantly share code, notes, and snippets.

@henrikbjorn
Last active July 16, 2019 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrikbjorn/d2eef51257a3937c5cdbd42836eeb012 to your computer and use it in GitHub Desktop.
Save henrikbjorn/d2eef51257a3937c5cdbd42836eeb012 to your computer and use it in GitHub Desktop.
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