| const {CleanWebpackPlugin} = require('clean-webpack-plugin'); |
| const path = require('path'); |
| const json5 = require('json5'); |
| const CopyWebpackPlugin = require('copy-webpack-plugin'); |
| const WebpackShellPluginNext = require('webpack-shell-plugin-next'); |
| |
| module.exports = (env, args) => { |
| let entry = { |
| // Content scripts |
| communityConsoleMain: './src/contentScripts/communityConsole/main.js', |
| communityConsoleStart: './src/contentScripts/communityConsole/start.js', |
| publicForum: './src/contentScripts/publicForum.js', |
| publicThread: './src/contentScripts/publicThread.js', |
| profile: './src/contentScripts/profile.js', |
| profileIndicator: './src/contentScripts/profileIndicator.js', |
| |
| // Injected JS |
| profileIndicatorInject: './src/injections/profileIndicator.js', |
| batchLockInject: './src/injections/batchLock.js', |
| |
| // Options page |
| optionsCommon: './src/optionsCommon.js', |
| }; |
| |
| // Background script (or service worker for MV3) |
| if (env.browser_target == 'chromium_mv3') |
| entry.sw = './src/sw.js'; |
| else |
| entry.background = './src/background.js'; |
| |
| let outputPath = path.join(__dirname, 'dist', env.browser_target); |
| |
| return { |
| entry, |
| output: { |
| filename: '[name].bundle.js', |
| path: outputPath, |
| clean: { |
| keep(asset) { |
| return asset.includes('static/') || asset.includes('manifest.json') || |
| asset.includes('LICENSE') || asset.includes('_locales'); |
| }, |
| }, |
| }, |
| plugins: [ |
| new CleanWebpackPlugin(), |
| new WebpackShellPluginNext({ |
| onBuildEnd: { |
| scripts: |
| ['go run tools/generateManifest.go -dest=' + |
| path.join(outputPath, 'manifest.json') + ' ' + |
| env.browser_target] |
| } |
| }), |
| new CopyWebpackPlugin({ |
| patterns: [ |
| { |
| from: path.join(__dirname, 'src/static'), |
| to: outputPath, |
| globOptions: { |
| ignore: ['**/OWNERS'], |
| } |
| }, |
| ] |
| }), |
| ], |
| // NOTE: Change to |
| // (args.mode == 'production' ? 'source-map' : 'inline-source-map') |
| // once https://crbug.com/212374 is fixed. |
| devtool: 'inline-source-map', |
| module: { |
| rules: [ |
| { |
| test: /\.json5$/, |
| type: 'json', |
| parser: { |
| parse: json5.parse, |
| }, |
| }, |
| ] |
| }, |
| }; |
| }; |