-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.ts
59 lines (53 loc) · 1.42 KB
/
webpack.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { resolve } from 'path';
import { Configuration } from 'webpack';
import glob from 'glob';
const isProduction = process.env.NODE_ENV === 'production';
const mode = isProduction ? 'production' : 'development';
console.info(`Build type: ${mode}`);
type LambdaFolder = {
path: string;
name: string;
};
const expr = /\.\/src\/(.+)\/app.ts$/;
const paths: LambdaFolder[] = glob
.sync('./src/**/app.ts')
.map((path: string) => path.match(expr))
.map((match: any) => ({ path: match[0], name: match[1] }));
console.log(paths);
const config: Configuration = {
mode: mode,
devtool: isProduction ? false : 'eval-source-map',
entry: paths.reduce((acc: any, lambda) => {
acc[lambda.name] = lambda.path;
return acc;
}, {}),
externals: isProduction ? ['aws-sdk'] : [],
output: {
filename: '[name]/app.js',
libraryTarget: 'commonjs2',
path: resolve(__dirname, 'dist'),
devtoolModuleFilenameTemplate: '[absolute-resource-path]',
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'esbuild-loader',
exclude: /node_modules/,
options: { loader: 'ts', target: 'es2015' },
},
],
},
resolve: {
extensions: ['.js', '.ts'],
},
target: 'node',
plugins: [
function () {
this.hooks.done.tap('BuildStatsPlugin', function () {
console.log('>>> ' + new Date().toLocaleTimeString() + ' <<<');
});
},
],
};
export default config;