-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
54 lines (51 loc) · 1.36 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
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ZipPlugin = require('zip-webpack-plugin');
const fs = require('fs');
const manifestJson = JSON.parse(fs.readFileSync('src/manifest.json', 'utf-8'));
const name = manifestJson.name.replace(/[^a-z0-9]/gi, '-').toLowerCase();
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
module.exports = {
entry: {
sw: './src/js/sw.js',
popup: './src/popup/popup.js'
},
output: {
path: path.join(__dirname, '/dist'),
filename: '[name].js',
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{
context: 'src/',
from: 'popup'
},
{
context: 'src/',
from: 'manifest.json',
transform: function (content) {
content = JSON.parse(content.toString());
delete content.key;
// generates the manifest file using the package.json version
return Buffer.from(
JSON.stringify({
...content,
version: packageJson.version,
})
);
},
},
{
context: 'src/',
from: 'icons'
}
]
}),
new ZipPlugin({
path: '../releases',
filename: `${name}-${packageJson.version}.zip`,
})
],
mode: 'production'
};