-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
webpack.config.ts
82 lines (78 loc) · 2.77 KB
/
webpack.config.ts
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
/* eslint-disable import/no-namespace */
import * as path from 'path';
import * as fs from 'fs';
import merge from 'merge';
import * as CopyPlugin from 'copy-webpack-plugin';
const dev = process.argv.includes('--mode=development');
const knownBrowsers = new Set(['chrome', 'firefox', 'safari', 'edge']);
const browser = process.env.KW_BROWSER || 'chrome';
if (!knownBrowsers.has(browser)) {
throw new Error(`Unknown browser: ${browser}`);
}
// eslint-disable-next-line import/no-default-export,no-restricted-syntax
export default {
entry: {
'background': './src/background/init.ts',
'content-keeweb': './src/content/content-keeweb.ts',
'content-page': './src/content/content-page.ts',
'options': './src/options/index.tsx'
},
output: {
filename: 'js/[name].js',
path: path.resolve('dist', browser)
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
alias: {
background: path.resolve('src/background'),
common: path.resolve('src/common'),
content: path.resolve('src/content'),
options: path.resolve('src/options')
},
extensions: ['.tsx', '.ts', '.js']
},
optimization: {
minimize: false
},
plugins: [
new CopyPlugin({
patterns: [
{ from: '_locales', to: '_locales' },
{ from: 'icons', to: 'icons' },
{ from: 'pages', to: 'pages' },
{ from: `img/${browser}`, to: 'img' },
{ from: 'styles', to: 'styles' },
{
from: 'manifest.json',
transform: (content) => {
const manifest = <chrome.runtime.Manifest>JSON.parse(content.toString());
const patchFiles = [`manifest.${browser}.json`];
if (dev) {
patchFiles.push('manifest.dev.json');
}
for (const patchFile of patchFiles) {
if (!fs.existsSync(patchFile)) {
continue;
}
const patchData = <chrome.runtime.Manifest>(
JSON.parse(fs.readFileSync(patchFile, 'utf8'))
);
merge.recursive(manifest, patchData);
}
const str = JSON.stringify(manifest, null, 2);
content = Buffer.from(str, 'utf8');
return content;
}
}
]
})
]
};