forked from iodepo/OceanBestPractices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
97 lines (85 loc) · 2.35 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// @ts-check
const _ = require('lodash');
const path = require('path');
const { readdir } = require('fs/promises');
/**
* @typedef {import('webpack').Configuration} Configuration
*/
/** @type {(f: string) => boolean} */
const isTestFile = (f) => f.endsWith('.test.js') || f.endsWith('.test.ts');
/** @type {(f: string) => boolean} */
const isNotTestFile = _.negate(isTestFile);
/** @type {(f: string) => boolean} */
const isSourceFile = (f) => f.endsWith('.js') || f.endsWith('.ts');
/**
* @param {string} entriesPath
* @param {string} prefix
* @returns {Promise<import('webpack').EntryObject>}
*/
const getEntries = async (entriesPath, prefix) => {
const files = await readdir(entriesPath);
return _(files)
.filter((f) => isNotTestFile(f))
.filter((f) => isSourceFile(f))
.map((f) => {
const { name } = path.parse(f);
return [
`${prefix}-${name}`,
{
import: path.resolve(path.join(entriesPath, f)),
filename: path.join(prefix, name, 'lambda.js'),
},
];
})
.fromPairs()
.value();
};
/** @type {() => Promise<Configuration>} */
const config = async () => {
const apiEntries = await getEntries(path.join('api', 'lambdas'), 'api');
const ingestEntries = await getEntries(
path.join('ingest', 'lambdas'),
'ingest'
);
return {
target: 'node',
node: { __dirname: true },
mode: process.env['NODE_ENV'] === 'production' ? 'production' : 'development',
entry: {
...apiEntries,
...ingestEntries,
neptuneBulkLoaderTask: {
import: './neptune-bulk-loader/task.ts',
filename: './neptune-bulk-loader/task/index.js',
},
neptuneBulkLoaderTaskLauncher: {
import: './neptune-bulk-loader/task-launcher.ts',
filename: './neptune-bulk-loader/task-launcher/lambda.js',
},
},
module: {
rules: [
{
test: /\.ts$/,
use: {
loader: 'ts-loader',
options: {
configFile: 'tsconfig-webpack.json',
},
},
exclude: /node_modules/,
},
],
},
devtool: 'source-map',
externals: { 'aws-sdk': 'aws-sdk' },
resolve: {
extensions: ['.ts', '...'],
},
output: {
path: path.join(process.cwd(), 'dist'),
library: { type: 'commonjs' },
},
};
};
module.exports = config;