-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
75 lines (69 loc) · 1.91 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
const path = require('path');
const { readdirSync, statSync } = require('fs');
const exec = require('child_process').execSync;
const getAllFiles = function (dirPath, arrayOfFiles) {
files = readdirSync(dirPath)
arrayOfFiles = arrayOfFiles || []
files.forEach(function (file) {
if (statSync(dirPath + "/" + file).isDirectory()) {
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles)
} else {
arrayOfFiles.push(`./${dirPath}/${file}`)
}
})
return arrayOfFiles
}
const dir = 'src/handlers';
const entry = getAllFiles(dir)
.filter(item => /\.(t|j)s$/.test(item))
.filter(item => !/\.d\.(t|j)s$/.test(item))
.reduce((acc, fileName) => ({
...acc,
[path.basename(fileName).replace(/\.(t|j)s$/, '')]: `${fileName}`
}), {})
const distFolder = 'bin';
const distPath = path.resolve(process.cwd(), distFolder);
console.log(entry)
module.exports = {
entry,
output: {
path: distPath
},
mode: 'production',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
modules: ['node_modules'],
extensions: ['.tsx', '.ts', '.js', '.json'],
},
target: 'node',
mode: 'production',
plugins: [
{
apply: compiler => {
compiler.hooks.done.tap(
'ZipPlugin',
() => {
Object.keys(entry).forEach(name => {
exec(`zip ${name}.zip ${name}.js`, { cwd: distPath })
//exec(`7z a ${name}.zip ${name}.js`, { cwd: distPath })// FOR WINDOWS
})
exec(`rm *.js`, { cwd: distPath })
//exec(`del *.js`, { cwd: distPath }); //FOR WINDOWS
console.info(
'produced deployment packages:\n\n',
Object.keys(entry).map(name => ' 💾 ./' + path.join('./', distFolder, `${name}.zip`)).join('\n\n '),
'\n'
);
});
}
}
]
};