-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
webpack.config.js
38 lines (32 loc) · 1.59 KB
/
webpack.config.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
37
38
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-param-reassign */
const path = require('path');
const dotenv = require('dotenv');
const _ = require('underscore');
const custom = require('../config/webpack/webpack.common')({
envFile: '../.env.production',
});
const env = dotenv.config({path: path.resolve(__dirname, '../.env.staging')}).parsed;
module.exports = ({config}) => {
config.resolve.alias = {
'react-native-config': 'react-web-config',
'react-native$': 'react-native-web',
'@react-native-community/netinfo': path.resolve(__dirname, '../__mocks__/@react-native-community/netinfo.js'),
};
// Necessary to overwrite the values in the existing DefinePlugin hardcoded to the Config staging values
const definePluginIndex = _.findIndex(config.plugins, plugin => plugin.constructor.name === 'DefinePlugin');
config.plugins[definePluginIndex].definitions.__REACT_WEB_CONFIG__ = JSON.stringify(env);
config.resolve.extensions.push('.web.js', '.website.js');
const babelRulesIndex = _.findIndex(custom.module.rules, rule => rule.loader === 'babel-loader');
const babelRule = custom.module.rules[babelRulesIndex];
config.module.rules.push(babelRule);
// Allows loading SVG - more context here https://github.com/storybookjs/storybook/issues/6188
const fileLoaderRule = _.find(config.module.rules, rule => rule.test && rule.test.test('.svg'));
fileLoaderRule.exclude = /\.svg$/;
config.module.rules.push({
test: /\.svg$/,
enforce: 'pre',
loader: require.resolve('@svgr/webpack'),
});
return config;
};