-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
83 lines (73 loc) · 2.06 KB
/
webpack.config.js
File metadata and controls
83 lines (73 loc) · 2.06 KB
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
const path = require('path')
const archiver = require('archiver')
const fs = require('fs')
class ZipPlugin {
apply(compiler) {
compiler.hooks.afterEmit.tapAsync('ZipPlugin', (compilation, callback) => {
const outputPath = path.join(__dirname, 'dist')
const outputFilePath = path.join(outputPath, 'bundle.zip')
if (!fs.existsSync(outputPath)) {
console.error(`Output directory "${outputPath}" does not exist.`)
return callback(new Error(`Output directory "${outputPath}" does not exist.`))
}
const output = fs.createWriteStream(outputFilePath)
const archive = archiver('zip', { zlib: { level: 9 } })
output.on('close', () => {
console.log(`bundle.zip has been created (${archive.pointer()} total bytes)`)
callback()
})
archive.on('error', (err) => {
console.error('Error during zipping process:', err)
return callback(err)
})
archive.pipe(output)
fs.readdir(outputPath, (err, files) => {
if (err) {
console.error('Error reading output directory:', err)
return callback(err)
}
files.forEach((file) => {
if (file !== 'bundle.zip') {
const filePath = path.join(outputPath, file)
if (fs.statSync(filePath).isFile()) {
archive.file(filePath, { name: file })
} else if (fs.statSync(filePath).isDirectory()) {
archive.directory(filePath, file)
}
}
})
archive.finalize()
})
})
}
}
module.exports = {
entry: './src/handler.ts',
target: 'node',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'index.js',
libraryTarget: 'commonjs2'
},
resolve: {
extensions: ['.ts', '.js']
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
mode: 'production',
optimization: {
minimize: true,
usedExports: true
},
externals: {
'aws-sdk': 'commonjs aws-sdk'
},
plugins: [new ZipPlugin()]
}