-
Notifications
You must be signed in to change notification settings - Fork 1
/
config-overrides.js
100 lines (95 loc) · 3.55 KB
/
config-overrides.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
// our packages that will now be included in the CRA build step
const appIncludes = [
resolveApp('src'),
resolveApp('../components/src'),
resolveApp('node_modules/react-native-vector-icons'),
];
const babelLoaderConfiguration = {
test: /\.js$/,
// Add every directory that needs to be compiled by Babel during the build.
include: [
path.resolve(appDirectory, 'index.web.js'),
path.resolve(appDirectory, 'src'),
path.resolve(appDirectory, 'node_modules/react-native-uncompiled'),
path.resolve(appDirectory, 'node_modules/react-native-vector-icons'),
path.resolve(appDirectory, 'node_modules/react-native-gesture-handler'),
],
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
// The 'metro-react-native-babel-preset' preset is recommended to match React Native's packager
presets: ['module:metro-react-native-babel-preset'],
// Re-write paths to import only the modules needed by the app
plugins: ['react-native-web'],
},
},
};
// const babelLoaderConfiguration = {
// test: /\.js$/,
// include: [
// path.resolve(appDirectory, 'index.web.js'),
// path.resolve(appDirectory, 'src'),
// path.resolve(appDirectory, 'node_modules/react-native-uncompiled'),
// path.resolve(appDirectory, 'node_modules/react-native-vector-icons'),
// path.resolve(appDirectory, 'node_modules/react-native-elements'),
// ],
// use: {
// loader: 'babel-loader',
// options: {
// cacheDirectory: true,
// presets: ['react-native'],
// plugins: ['react-native-web'],
// },
// },
// };
// const compileNodeModules = [
// // Add every react-native package that needs compiling
// // 'react-native-gesture-handler',
// 'react-native-vector-icons',
// ].map((moduleName) => path.resolve(appDirectory,
// `node_modules/${moduleName}`));
module.exports = function override(config, env) {
config.plugins.push(
new webpack.DefinePlugin({
// See: https://github.com/necolas/react-native-web/issues/349
__DEV__: JSON.stringify(true),
}),
);
config.resolve.alias = {
...(config.resolve.alias || {}),
// Transform all direct `react-native` imports to `react-native-web`
'react-native$': 'react-native-web',
};
config.module.rules.push(babelLoaderConfiguration),
config.module.rules.push({
test: /\.(jpe?g|png|gif|svg)$/i,
use: ['url-loader?limit=10000', 'img-loader'],
});
config.module.rules.push({
test: /\.ttf$/,
loader: 'url-loader', // or directly file-loader
include: path.resolve(__dirname, 'node_modules/react-native-vector-icons'),
});
// allow importing from outside of src folder
config.resolve.plugins = config.resolve.plugins.filter(
plugin => plugin.constructor.name !== 'ModuleScopePlugin',
);
// config.resolve.
// config.module.rules[0].include = appIncludes
// config.module.rules[1] = null
// config.module.rules[2].oneOf[1].include = appIncludes
// config.module.rules[2].oneOf[1].options.plugins = [
// require.resolve('babel-plugin-react-native-web'),
// ].concat(config.module.rules[2].oneOf[1].options.plugins)
// config.module.rules = config.module.rules.filter(Boolean)
// config.plugins.push(
// new webpack.DefinePlugin({ __DEV__: env !== 'production' })
// )
return config;
};