-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
66 lines (62 loc) · 1.8 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
const path = require('path')
const glob = require('glob')
const webpack = require('webpack')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin')
const smp = new SpeedMeasurePlugin()
// Credits: https://hackernoon.com/webpack-creating-dynamically-named-outputs-for-wildcarded-entry-files-9241f596b065
const entryArray = glob.sync('./src/**/lambda.ts')
const entryObject = entryArray.reduce((acc, item) => {
let name = path.dirname(item.replace('./src/', ''))
// conforms with Webpack entry API
// Example: { test: './src/test/lambda.ts' }
acc[name] = item
return acc
}, {})
const config = smp.wrap({
entry: entryObject,
devtool: 'source-map',
target: 'node',
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true
}
}
],
exclude: /node_modules/
}
]
},
optimization: {
minimize: false
},
plugins: [new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)],
resolve: {
extensions: ['.ts', '.js'],
symlinks: false,
cacheWithContext: false
},
// Output directive will generate build/<function-name>/lambda.js
output: {
filename: '[name]/lambda.js',
path: path.resolve(__dirname, 'build'),
devtoolModuleFilenameTemplate: '[absolute-resource-path]',
// credits to Rich Buggy!!!
libraryTarget: 'commonjs2'
}
})
if (process.env.BUNDLE_ANALYZER && process.env.BUNDLE_ANALYZER === 'true') {
config.plugins.push(new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: '../info/bundle-report.html',
openAnalyzer: false
}))
}
module.exports = config