|
1 | 1 | /* config-overrides.js */
|
2 |
| - |
3 |
| -module.exports = { |
4 |
| - // The function to use to create a webpack dev server configuration when running the development |
5 |
| - // server with 'npm run start' or 'yarn start'. |
6 |
| - // Example: set the dev server to use a specific certificate in https. |
7 |
| - devServer: function(configFunction) { |
8 |
| - // Return the replacement function for create-react-app to use to generate the Webpack |
9 |
| - // Development Server config. "configFunction" is the function that would normally have |
10 |
| - // been used to generate the Webpack Development server config - you can use it to create |
11 |
| - // a starting configuration to then modify instead of having to create a config from scratch. |
12 |
| - return function(proxy, allowedHost) { |
13 |
| - // Create the default config by calling configFunction with the proxy/allowedHost parameters |
14 |
| - const config = configFunction(proxy, allowedHost); |
15 |
| - |
16 |
| - config.headers = { |
17 |
| - 'Access-Control-Allow-Origin': '*', |
18 |
| - 'Access-Control-Allow-Methods': 'GET', |
19 |
| - 'Access-Control-Allow-Headers': |
20 |
| - 'X-Requested-With, content-type, Authorization', |
21 |
| - }; |
22 |
| - |
23 |
| - // Return your customised Webpack Development Server config. |
24 |
| - return config; |
25 |
| - }; |
26 |
| - }, |
| 2 | +const webpack = require('webpack'); |
| 3 | +module.exports = function override(config) { |
| 4 | + config.module.rules.push({ |
| 5 | + test: /\.mjs$/, |
| 6 | + include: /node_modules/, |
| 7 | + type: 'javascript/auto', |
| 8 | + }); |
| 9 | + const fallback = config.resolve.fallback || {}; |
| 10 | + Object.assign(fallback, { |
| 11 | + axios: false, |
| 12 | + fs: false, |
| 13 | + crypto: false, // require.resolve("crypto-browserify") can be polyfilled here if needed |
| 14 | + stream: false, // require.resolve("stream-browserify") can be polyfilled here if needed |
| 15 | + assert: false, // require.resolve("assert") can be polyfilled here if needed |
| 16 | + http: false, // require.resolve("stream-http") can be polyfilled here if needed |
| 17 | + https: false, // require.resolve("https-browserify") can be polyfilled here if needed |
| 18 | + os: false, // require.resolve("os-browserify") can be polyfilled here if needed |
| 19 | + url: false, // require.resolve("url") can be polyfilled here if needed |
| 20 | + zlib: false, // require.resolve("browserify-zlib") can be polyfilled here if needed |
| 21 | + }); |
| 22 | + config.resolve.fallback = fallback; |
| 23 | + config.plugins = (config.plugins || []).concat([ |
| 24 | + new webpack.ProvidePlugin({ |
| 25 | + process: 'process/browser', |
| 26 | + Buffer: ['buffer', 'Buffer'], |
| 27 | + }), |
| 28 | + ]); |
| 29 | + config.ignoreWarnings = [/Failed to parse source map/]; |
| 30 | + config.module.rules.push({ |
| 31 | + test: /\.(js|mjs|jsx)$/, |
| 32 | + enforce: 'pre', |
| 33 | + loader: require.resolve('source-map-loader'), |
| 34 | + resolve: { |
| 35 | + fullySpecified: false, |
| 36 | + }, |
| 37 | + }); |
| 38 | + config.module.rules = config.module.rules.map((rule) => { |
| 39 | + if (rule.oneOf instanceof Array) { |
| 40 | + rule.oneOf[rule.oneOf.length - 1].exclude = [ |
| 41 | + /\.(js|mjs|jsx|cjs|ts|tsx)$/, |
| 42 | + /\.html$/, |
| 43 | + /\.json$/, |
| 44 | + ]; |
| 45 | + } |
| 46 | + return rule; |
| 47 | + }); |
| 48 | + return config; |
27 | 49 | };
|
0 commit comments