Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 1 | const path = require('path'); |
| 2 | const json5 = require('json5'); |
| 3 | const CopyWebpackPlugin = require('copy-webpack-plugin'); |
| 4 | const WebpackShellPluginNext = require('webpack-shell-plugin-next'); |
| 5 | |
| 6 | module.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ínez | 43ec2b9 | 2021-07-16 18:44:54 +0200 | [diff] [blame] | 19 | xhrInterceptorInject: './src/injections/xhrInterceptor.js', |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 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, |
Adrià Vilanova Martínez | 85424b6 | 2021-07-11 21:52:00 +0200 | [diff] [blame] | 38 | clean: true, |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 39 | }, |
| 40 | plugins: [ |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 41 | 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 | }; |