|
| 1 | +const path = require('path'); |
| 2 | +const { mergeWithCustomize, unique } = require('webpack-merge'); |
1 | 3 | const { getBaseConfig } = require('@edx/frontend-build');
|
2 | 4 | // NOTE: This version of html-webpack-plugin must be the same major version as the one in
|
3 | 5 | // frontend-build to avoid potential issues.
|
| 6 | +const HtmlWebpackPlugin = require('html-webpack-plugin'); |
4 | 7 |
|
5 | 8 | /**
|
6 |
| - * This plugin configuration edits the default in webpack-prod for the following reasons: |
| 9 | + * This plugin configuration overrides the default in webpack-prod for the following reasons: |
7 | 10 | *
|
8 | 11 | * We need to have a custom html-webpack-plugin configuration to allow us to preconnect to
|
9 | 12 | * various domains. See the public/index.html file for the companion usage of this configuration.
|
10 | 13 | */
|
11 | 14 |
|
12 |
| -const config = getBaseConfig('webpack-prod'); |
| 15 | +const config = mergeWithCustomize({ |
| 16 | + customizeArray: unique( |
| 17 | + 'plugins', |
| 18 | + ['HtmlWebpackPlugin'], |
| 19 | + plugin => plugin.constructor && plugin.constructor.name, |
| 20 | + ), |
| 21 | +})( |
| 22 | + getBaseConfig('webpack-prod'), |
| 23 | + { |
| 24 | + plugins: [ |
| 25 | + // Generates an HTML file in the output directory. |
| 26 | + new HtmlWebpackPlugin({ |
| 27 | + inject: false, // Manually inject head and body tags in the template itself. |
| 28 | + template: path.resolve(__dirname, 'public/index.html'), |
| 29 | + FAVICON_URL: process.env.FAVICON_URL || null, |
| 30 | + OPTIMIZELY_PROJECT_ID: process.env.OPTIMIZELY_PROJECT_ID || null, |
| 31 | + preconnect: (() => { |
| 32 | + const preconnectDomains = [ |
| 33 | + 'https://api.segment.io', |
| 34 | + 'https://cdn.segment.com', |
| 35 | + 'https://www.google-analytics.com', |
| 36 | + ]; |
13 | 37 |
|
14 |
| -/* eslint-disable no-param-reassign */ |
15 |
| -config.plugins.forEach((plugin) => { |
16 |
| - if (plugin.constructor.name === 'HtmlWebpackPlugin') { |
17 |
| - const preconnectDomains = [ |
18 |
| - 'https://api.segment.io', |
19 |
| - 'https://cdn.segment.com', |
20 |
| - 'https://www.google-analytics.com', |
21 |
| - ]; |
| 38 | + if (process.env.LMS_BASE_URL) { |
| 39 | + preconnectDomains.push(process.env.LMS_BASE_URL); |
| 40 | + } |
22 | 41 |
|
23 |
| - if (process.env.LMS_BASE_URL) { |
24 |
| - preconnectDomains.push(process.env.LMS_BASE_URL); |
25 |
| - } |
| 42 | + if (process.env.OPTIMIZELY_PROJECT_ID) { |
| 43 | + preconnectDomains.push('https://logx.optimizely.com'); |
| 44 | + } |
26 | 45 |
|
27 |
| - if (process.env.OPTIMIZELY_PROJECT_ID) { |
28 |
| - preconnectDomains.push('https://logx.optimizely.com'); |
29 |
| - } |
30 |
| - |
31 |
| - plugin.userOptions.preconnect = preconnectDomains; |
32 |
| - } |
33 |
| -}); |
| 46 | + return preconnectDomains; |
| 47 | + })(), |
| 48 | + }), |
| 49 | + ], |
| 50 | + }, |
| 51 | +); |
34 | 52 |
|
35 | 53 | module.exports = config;
|
0 commit comments