blob: 312a2761aae45c31768c43920be8d01741e34dda [file] [log] [blame]
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +02001const path = require('path');
2const json5 = require('json5');
3const CopyWebpackPlugin = require('copy-webpack-plugin');
4const WebpackShellPluginNext = require('webpack-shell-plugin-next');
5
6module.exports = (env, args) => {
7 let entry = {
8 // Content scripts
9 communityConsoleMain: './src/contentScripts/communityConsole/main.js',
10 communityConsoleStart: './src/contentScripts/communityConsole/start.js',
11 publicForum: './src/contentScripts/publicForum.js',
12 publicThread: './src/contentScripts/publicThread.js',
13 profile: './src/contentScripts/profile.js',
14 profileIndicator: './src/contentScripts/profileIndicator.js',
15
16 // Injected JS
17 profileIndicatorInject: './src/injections/profileIndicator.js',
18 batchLockInject: './src/injections/batchLock.js',
Adrià Vilanova Martínez43ec2b92021-07-16 18:44:54 +020019 xhrInterceptorInject: './src/injections/xhrInterceptor.js',
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020020
21 // Options page
22 optionsCommon: './src/optionsCommon.js',
23 };
24
25 // Background script (or service worker for MV3)
26 if (env.browser_target == 'chromium_mv3')
27 entry.sw = './src/sw.js';
28 else
29 entry.background = './src/background.js';
30
31 let outputPath = path.join(__dirname, 'dist', env.browser_target);
32
33 return {
34 entry,
35 output: {
36 filename: '[name].bundle.js',
37 path: outputPath,
Adrià Vilanova Martínez85424b62021-07-11 21:52:00 +020038 clean: true,
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020039 },
40 plugins: [
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020041 new WebpackShellPluginNext({
42 onBuildEnd: {
43 scripts:
44 ['go run tools/generateManifest.go -dest=' +
45 path.join(outputPath, 'manifest.json') + ' ' +
46 env.browser_target]
47 }
48 }),
49 new CopyWebpackPlugin({
50 patterns: [
51 {
52 from: path.join(__dirname, 'src/static'),
53 to: outputPath,
54 globOptions: {
55 ignore: ['**/OWNERS'],
56 }
57 },
58 ]
59 }),
60 ],
61 // NOTE: Change to
62 // (args.mode == 'production' ? 'source-map' : 'inline-source-map')
63 // once https://crbug.com/212374 is fixed.
64 devtool: 'inline-source-map',
65 module: {
66 rules: [
67 {
68 test: /\.json5$/,
69 type: 'json',
70 parser: {
71 parse: json5.parse,
72 },
73 },
74 ]
75 },
76 };
77};