-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
59 lines (57 loc) · 1.41 KB
/
webpack.config.js
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
const CopyPlugin = require('copy-webpack-plugin');
const glob = require('glob');
const path = require('node:path');
const ZipPlugin = require("zip-webpack-plugin");
// Automatically find all Lambda entry points
const entry = glob.sync('./service/*.ts').reduce((acc, file) => {
const name = path.relative('./service', file).replace(/\.ts$/, '');
acc[name] = file;
return acc;
}, {});
module.exports = {
context: __dirname,
mode: 'production',
entry: entry,
// devtool: 'source-map',
stats: 'normal',
resolve: {
extensions: ['.tsx', '.ts', '.js', '.json'],
modules: ['node_modules'],
},
output: {
libraryTarget: 'commonjs2',
path: path.join(__dirname, 'dist'),
filename: '[name]/index.js',
},
target: 'node',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
optimization: {
usedExports: true,
providedExports: true,
sideEffects: true,
minimize: false,
},
plugins: [
new CopyPlugin({
patterns: [
{ from: 'service/views', to: 'api/views' },
],
}),
// compress each service into it's own .zip file
...Object.keys(entry).map(entryName => {
return new ZipPlugin({
filename: `../${entryName}.zip`,
include: new RegExp(`${entryName}/.*`),
pathMapper: (assetPath) => assetPath.replace(`${entryName}/`, ''),
});
}),
],
};