Skip to content

Commit

Permalink
fix: build typescript automatically using webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
JoyceBabu committed May 4, 2021
1 parent 9679900 commit df2ff12
Show file tree
Hide file tree
Showing 8 changed files with 14,849 additions and 7,916 deletions.
20,370 changes: 12,788 additions & 7,582 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@
"description": "A serverless DDNS service using AWS Lambda",
"main": "index.js",
"dependencies": {
"bcryptjs": "^2.4.3",
"cloudflare": "^2.7.0"
"bcryptjs": "^2.4.3"
},
"devDependencies": {
"@babel/core": "^7.14.0",
"@babel/preset-env": "^7.14.1",
"@babel/preset-typescript": "^7.13.0",
"@types/aws-lambda": "^8.10.76",
"@types/bcryptjs": "^2.4.2",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.2",
"copy-webpack-plugin": "^8.1.1",
"eslint": "^7.25.0",
"fork-ts-checker-webpack-plugin": "^6.2.6",
"serverless": "^2.29.0",
"serverless-domain-manager": "^5.1.0",
"typescript": "^4.2.4"
"serverless-webpack": "^5.4.2",
"typescript": "^4.2.4",
"webpack": "^5.36.2",
"webpack-node-externals": "^3.0.0"
},
"engines": {
"node": ">=14"
Expand Down
10 changes: 7 additions & 3 deletions serverless.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
service: ddns-updater
plugins:
- serverless-domain-manager
- serverless-webpack
provider:
name: aws
runtime: nodejs14.x
Expand Down Expand Up @@ -32,10 +33,13 @@ custom:
domainName: ${self:custom.domain}
stage: ${self:custom.stage}
createRoute53Record: true

webpack:
webpackConfig: 'webpack.config.js'
includeModules:
forceExclude:
- aws-sdk
package:
patterns:
- 'src/**'
individually: true

functions:
index:
Expand Down
2 changes: 1 addition & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import bcrypt from 'bcryptjs';
import { IConfig, Loader as ConfigLoader } from './config.js';
import { IConfig, Loader as ConfigLoader } from './config';
import { Callback, Context, APIGatewayTokenAuthorizerEvent } from 'aws-lambda';

async function validate(username: string, password: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/ddns-updater.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import Route53 from './providers/route53.js';
import Route53 from './providers/route53';
import { IHostConfig} from './config';

class DdnsUpdater {
Expand Down
4 changes: 2 additions & 2 deletions src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import DdnsUpdater from './ddns-updater.js';
import { IConfig, IHostConfig, Loader as ConfigLoader } from './config.js';
import DdnsUpdater from './ddns-updater';
import { IConfig, IHostConfig, Loader as ConfigLoader } from './config';
import { APIGatewayEvent, Callback, Context } from 'aws-lambda';

function createResponse(statusCode: number, body: string) {
Expand Down
57 changes: 57 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const slsw = require('serverless-webpack');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');


const isLocal = slsw.lib.webpack.isLocal;

module.exports = {
mode: isLocal ? 'development' : 'production',
entry: slsw.lib.entries,
externals: [nodeExternals()],
devtool: 'source-map',
resolve: {
extensions: [ '.js', '.jsx', '.json', '.ts', '.tsx' ]
},
output: {
libraryTarget: 'commonjs2',
path: path.join(__dirname, '.webpack'),
filename: '[name].js'
},
optimization: {
minimize: false
},
target: 'node',
module: {
rules: [
{
test: /.(js|ts)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{ targets: { node: '14' }, useBuiltIns: 'usage', corejs: 3 }
]
]
}
}
]
}
]
},
plugins: [
new ForkTsCheckerWebpackPlugin(),
new CopyPlugin({
patterns: [
{ from: "./config.json", to: "./config.json" },
]
}),
]
};
Loading

0 comments on commit df2ff12

Please sign in to comment.