-
Notifications
You must be signed in to change notification settings - Fork 340
/
Copy pathconfig.js
92 lines (83 loc) · 2.72 KB
/
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import path from 'path'
import initLoaderRules from './loaders'
import initPlugins from './plugins'
import initMinimizers from './minimizers'
import { externalTsModules } from './external'
import { buildingManifestV3 } from './util'
export const extensions = ['.ts', '.tsx', '.js', '.jsx']
export const entry = {
background: buildingManifestV3
? './src/background-mv3.ts'
: './src/background.ts',
popup: './src/popup/index.tsx',
content_script: './src/content-scripts/content_script/global_webpage.ts',
content_script_pdfjs:
'./src/content-scripts/content_script/global_pdfjs.ts',
content_script_in_page_ui_injections:
'./src/content-scripts/content_script/in-page-ui-injections.ts',
content_script_ribbon: './src/content-scripts/content_script/ribbon.ts',
content_script_tooltip: './src/content-scripts/content_script/tooltip.ts',
content_script_sidebar: './src/content-scripts/content_script/sidebar.ts',
options: './src/options/options.tsx',
}
export const output = {
path: path.resolve(__dirname, '../extension'),
filename: '[name].js',
}
export default ({ context = __dirname, mode = 'development', ...opts }) => {
const aliases = {
src: path.resolve(context, './src'),
}
for (const [moduleAlias, modulePath] of Object.entries(externalTsModules)) {
const extPath = path.resolve(context, `./external/${modulePath}/ts`)
Object.assign(aliases, {
[`${moduleAlias}$`]: extPath,
[`${moduleAlias}/lib`]: extPath,
})
}
const conf = {
context,
entry,
output,
mode,
devtool:
mode === 'development'
? 'inline-cheap-module-source-map'
: 'hidden-source-map',
plugins: initPlugins({
...opts,
mode,
htmlTemplates: {
options: path.resolve(__dirname, './template-options.html'),
popup: path.resolve(__dirname, './template-popup.html'),
},
}),
module: {
rules: initLoaderRules({ ...opts, mode, context }),
},
resolve: {
extensions,
symlinks: false,
mainFields: ['browser', 'main', 'module'],
alias: aliases,
},
stats: {
assetsSort: 'size',
children: false,
cached: false,
cachedAssets: false,
entrypoints: false,
excludeAssets: /\.(png|svg)/,
maxModules: 5,
},
performance: {
hints: false,
},
}
if (mode === 'production') {
conf.optimization = {
minimizer: initMinimizers(),
}
}
return conf
}