-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwith-polyfill.js
36 lines (31 loc) · 1.2 KB
/
with-polyfill.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const path = require('path');
/**
* Next.js config mixin that adds polyfills.js to the beginning of the webpack
* entries. This file contains the polyfills that are necessary for our common
* libraries (like React, Emotion, and Formik/Yup) to work across browsers.
*
* For polyfills that our own code needs, we use preset-env’s "usage" behavior,
* which is set in @cityofboston/config-babel/next.
*
* While we only officially support IE11+ and latest versions of evergreen
* browsers, if we can support someone’s older phone by dropping in the right
* polyfill that seems worth it to do.
*/
module.exports = () => nextConfig =>
Object.assign({}, nextConfig, {
webpack(config, options) {
const originalEntry = config.entry;
config.entry = async () => {
const entries = await originalEntry();
const polyfillsPath = path.resolve(__dirname, 'polyfills.js');
if (entries['main.js'] && !entries['main.js'].includes(polyfillsPath)) {
entries['main.js'].unshift(polyfillsPath);
}
return entries;
};
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options);
}
return config;
},
});