blob: 6843f0dfbff91af2347945af31ca5aa792470a46 [file] [log] [blame]
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +02001const {CleanWebpackPlugin} = require('clean-webpack-plugin');
2const path = require('path');
3const json5 = require('json5');
4const CopyWebpackPlugin = require('copy-webpack-plugin');
5const WebpackShellPluginNext = require('webpack-shell-plugin-next');
6
7module.exports = (env, args) => {
8 let entry = {
9 // Content scripts
10 communityConsoleMain: './src/contentScripts/communityConsole/main.js',
11 communityConsoleStart: './src/contentScripts/communityConsole/start.js',
12 publicForum: './src/contentScripts/publicForum.js',
13 publicThread: './src/contentScripts/publicThread.js',
14 profile: './src/contentScripts/profile.js',
15 profileIndicator: './src/contentScripts/profileIndicator.js',
16
17 // Injected JS
18 profileIndicatorInject: './src/injections/profileIndicator.js',
19 batchLockInject: './src/injections/batchLock.js',
20
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,
38 clean: {
39 keep(asset) {
40 return asset.includes('static/') || asset.includes('manifest.json') ||
41 asset.includes('LICENSE') || asset.includes('_locales');
42 },
43 },
44 },
45 plugins: [
46 new CleanWebpackPlugin(),
47 new WebpackShellPluginNext({
48 onBuildEnd: {
49 scripts:
50 ['go run tools/generateManifest.go -dest=' +
51 path.join(outputPath, 'manifest.json') + ' ' +
52 env.browser_target]
53 }
54 }),
55 new CopyWebpackPlugin({
56 patterns: [
57 {
58 from: path.join(__dirname, 'src/static'),
59 to: outputPath,
60 globOptions: {
61 ignore: ['**/OWNERS'],
62 }
63 },
64 ]
65 }),
66 ],
67 // NOTE: Change to
68 // (args.mode == 'production' ? 'source-map' : 'inline-source-map')
69 // once https://crbug.com/212374 is fixed.
70 devtool: 'inline-source-map',
71 module: {
72 rules: [
73 {
74 test: /\.json5$/,
75 type: 'json',
76 parser: {
77 parse: json5.parse,
78 },
79 },
80 ]
81 },
82 };
83};