Comments (1)
As a temp. solution, I have commented out, as I can see that is not used later in resources in ISamFunction.
So final webpack.config.ts in my case looks like:
import { resolve } from 'path';
import { readFileSync } from 'fs';
import { yamlParse } from 'yaml-cfn';
import { Configuration } from 'webpack';
/* eslint-disable */
const { compilerOptions } = require('./tsconfig.json');
/* eslint-enable */
/** Webpack Config Variables */
const conf = {
prodMode: process.env.NODE_ENV === 'production',
templatePath: '../../template.yaml'
};
/**
* Parsing tsconfig.json paths to resolve aliases
*/
const tsPaths = Object.keys(compilerOptions.paths).reduce(
(paths, path) =>
Object.assign(paths, { [`${path}`]: resolve(__dirname, compilerOptions.paths[path][0]) }),
{}
);
/**
* Parsing template.yaml file for function dir locations
*/
/** Interface for AWS SAM Function */
const { Resources: resources } = yamlParse(readFileSync(conf.templatePath, 'utf-8'));
interface ISamFunction {
Type: string;
Properties: {
AssumeRolePolicyDocument?: JSON;
AutoPublishAlias?: string;
AutoPublishCodeSha256?: string;
CodeUri?: string;
Description?: string;
Environment?: {
Variables: {
[key: string]: string;
};
};
// Events?: EventSource;
FunctionName?: string;
Handler: string;
Layers?: { [Ref: string]: string }[];
Runtime: string;
Timeout?: number;
Tracing?: string;
VersionDescription?: string;
};
}
const entries = Object.values(resources)
.filter((resource: ISamFunction) => resource.Type === 'AWS::Serverless::Function')
.filter(
(resource: ISamFunction) =>
resource.Properties.Runtime && resource.Properties.Runtime.startsWith('nodejs')
)
.map((resource: ISamFunction) => ({
filename: resource.Properties.Handler.split('.')[0],
entryPath: resource.Properties.CodeUri.split('/').splice(3).join('/'),
}))
.reduce(
(resources, resource) =>
Object.assign(resources, {
[`${resource.filename}`]: `./src/${resource.entryPath}${resource.filename}.ts`,
}),
{}
);
/**
* Webpack Config
*/
const webpackConfig: Configuration = {
entry: entries,
target: 'node',
mode: conf.prodMode ? 'production' : 'development',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: tsPaths,
},
output: {
path: resolve(__dirname, 'dist'),
filename: '[name].js',
libraryTarget: 'commonjs2',
},
devtool: 'source-map',
plugins: [],
};
export default webpackConfig;
from serverless-sam-typescript-boilerplate.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serverless-sam-typescript-boilerplate.