-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
61 lines (59 loc) · 1.56 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
const path = require('path');
const { readdirSync } = require('fs');
const exec = require('child_process').execSync;
const dir = 'src/handlers'
const entry = readdirSync(dir)
.filter(item => /\.(t|j)s$/.test(item))
.filter(item => !/\.d\.(t|j)s$/.test(item))
.filter(item => !item.includes('e2e'))
.reduce((acc, fileName) => ({
...acc,
[fileName.replace(/\.(t|j)s$/, '')]: `./${dir}/${fileName}`
}), {})
const distFolder = 'dist'
const distPath = path.resolve(process.cwd(), distFolder)
module.exports = {
entry,
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
libraryTarget: 'commonjs2'
},
mode: 'production',
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/
},
],
},
resolve: {
modules: ['node_modules'],
extensions: [ '.tsx', '.ts', '.js', '.json' ],
},
target: 'node',
stats: 'minimal',
devtool: 'source-map',
plugins: [
{
apply: compiler => {
compiler.hooks.done.tap(
'ZipPlugin',
(a,b,c) => {
Object.keys(entry).forEach(name => {
exec(`zip -D ${name}.zip -r ${name}.js -r ${name}.js.map`, { cwd: distPath })
})
exec(`rm *.js`, { cwd: distPath })
exec(`rm *.map`, { cwd: distPath })
console.info(
'produced deployment packages:\n\n',
Object.keys(entry).map(name => ' 💾 ./' + path.join('./', distFolder, `${name}.zip`)).join('\n\n '),
'\n'
);
});
}
}
]
};