blob: 615ae14cf98e5a6cf609c9174c7b2fa9bf181647 [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
Adrià Vilanova Martínez43d0a7b2021-08-28 01:21:17 +02006// Pontoon uses their own locale set. This array lets us convert those locales
7// to the ones accepted by Chrome, Firefox, etc.
8const localeOverrides = [
9 {
10 pontoonLocale: 'pt-rBR',
11 webExtLocale: 'pt', // This way it targets both 'pt_BR' and 'pt_PT'
12 },
13];
14
15const getCopyPluginsForOverridenLocales = outputPath => {
16 return localeOverrides.map(l => {
17 return new CopyWebpackPlugin({
18 patterns: [
19 {
20 from: path.join(__dirname, 'src/static/_locales/' + l.pontoonLocale),
21 to: path.join(outputPath, '_locales/' + l.webExtLocale),
22 globOptions: {
23 ignore: ['**/OWNERS', '**.md'],
24 }
25 },
26 ]
27 });
28 });
29};
30
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020031module.exports = (env, args) => {
32 let entry = {
33 // Content scripts
34 communityConsoleMain: './src/contentScripts/communityConsole/main.js',
35 communityConsoleStart: './src/contentScripts/communityConsole/start.js',
36 publicForum: './src/contentScripts/publicForum.js',
37 publicThread: './src/contentScripts/publicThread.js',
38 profile: './src/contentScripts/profile.js',
39 profileIndicator: './src/contentScripts/profileIndicator.js',
40
41 // Injected JS
42 profileIndicatorInject: './src/injections/profileIndicator.js',
43 batchLockInject: './src/injections/batchLock.js',
Adrià Vilanova Martínez43ec2b92021-07-16 18:44:54 +020044 xhrInterceptorInject: './src/injections/xhrInterceptor.js',
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020045
46 // Options page
47 optionsCommon: './src/optionsCommon.js',
48 };
49
50 // Background script (or service worker for MV3)
51 if (env.browser_target == 'chromium_mv3')
52 entry.sw = './src/sw.js';
53 else
54 entry.background = './src/background.js';
55
56 let outputPath = path.join(__dirname, 'dist', env.browser_target);
57
Adrià Vilanova Martínez43d0a7b2021-08-28 01:21:17 +020058 let overridenLocalePaths =
59 localeOverrides.map(l => '**/_locales/' + l.pontoonLocale);
60
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020061 return {
62 entry,
63 output: {
64 filename: '[name].bundle.js',
65 path: outputPath,
Adrià Vilanova Martínez85424b62021-07-11 21:52:00 +020066 clean: true,
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020067 },
68 plugins: [
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020069 new WebpackShellPluginNext({
70 onBuildEnd: {
71 scripts:
72 ['go run tools/generateManifest.go -dest=' +
73 path.join(outputPath, 'manifest.json') + ' ' +
74 env.browser_target]
75 }
76 }),
77 new CopyWebpackPlugin({
78 patterns: [
79 {
80 from: path.join(__dirname, 'src/static'),
81 to: outputPath,
82 globOptions: {
Adrià Vilanova Martínez43d0a7b2021-08-28 01:21:17 +020083 ignore: ['**/OWNERS', '**.md', ...overridenLocalePaths],
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020084 }
85 },
86 ]
87 }),
Adrià Vilanova Martínez43d0a7b2021-08-28 01:21:17 +020088 ...getCopyPluginsForOverridenLocales(outputPath),
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020089 ],
90 // NOTE: Change to
91 // (args.mode == 'production' ? 'source-map' : 'inline-source-map')
92 // once https://crbug.com/212374 is fixed.
93 devtool: 'inline-source-map',
94 module: {
95 rules: [
96 {
97 test: /\.json5$/,
98 type: 'json',
99 parser: {
100 parse: json5.parse,
101 },
102 },
103 ]
104 },
105 };
106};