blob: bdd988e949f649761d1f9c566ee9b6ce49a2f8e2 [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',
19
20 // Options page
21 optionsCommon: './src/optionsCommon.js',
22 };
23
24 // Background script (or service worker for MV3)
25 if (env.browser_target == 'chromium_mv3')
26 entry.sw = './src/sw.js';
27 else
28 entry.background = './src/background.js';
29
30 let outputPath = path.join(__dirname, 'dist', env.browser_target);
31
32 return {
33 entry,
34 output: {
35 filename: '[name].bundle.js',
36 path: outputPath,
Adrià Vilanova Martínez85424b62021-07-11 21:52:00 +020037 clean: true,
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020038 },
39 plugins: [
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020040 new WebpackShellPluginNext({
41 onBuildEnd: {
42 scripts:
43 ['go run tools/generateManifest.go -dest=' +
44 path.join(outputPath, 'manifest.json') + ' ' +
45 env.browser_target]
46 }
47 }),
48 new CopyWebpackPlugin({
49 patterns: [
50 {
51 from: path.join(__dirname, 'src/static'),
52 to: outputPath,
53 globOptions: {
54 ignore: ['**/OWNERS'],
55 }
56 },
57 ]
58 }),
59 ],
60 // NOTE: Change to
61 // (args.mode == 'production' ? 'source-map' : 'inline-source-map')
62 // once https://crbug.com/212374 is fixed.
63 devtool: 'inline-source-map',
64 module: {
65 rules: [
66 {
67 test: /\.json5$/,
68 type: 'json',
69 parser: {
70 parse: json5.parse,
71 },
72 },
73 ]
74 },
75 };
76};