|
| 1 | +const { getDefaultConfig } = require('expo/metro-config'); |
| 2 | + |
1 | 3 | const path = require('path'); |
2 | 4 | const fs = require('fs'); |
3 | | -const { getDefaultConfig } = require('expo/metro-config'); |
4 | 5 |
|
5 | | -const packagesRoot = path.resolve(__dirname, '../../packages'); |
6 | | -const docToolsRoot = path.resolve(__dirname, '../../doc-tools'); |
| 6 | +const projectRoot = __dirname; |
| 7 | +const packagesRoot = path.resolve(projectRoot, '../../packages'); |
| 8 | +const docToolsRoot = path.resolve(projectRoot, '../../doc-tools'); |
7 | 9 |
|
8 | | -const localPkgs = fs.readdirSync(packagesRoot); |
9 | | -const docToolksPkgs = fs.readdirSync(docToolsRoot); |
| 10 | +const packagesDirs = fs.readdirSync(packagesRoot); |
| 11 | +const docToolsDirs = fs.readdirSync(docToolsRoot); |
10 | 12 |
|
11 | | -const watchFolders = localPkgs |
12 | | - .map((f) => path.join(packagesRoot, f)) |
13 | | - .concat(docToolksPkgs.map((f) => path.join(docToolsRoot, f))); |
| 13 | +const config = getDefaultConfig(projectRoot); |
14 | 14 |
|
15 | | -module.exports = (async () => { |
16 | | - const { |
17 | | - resolver: { assetExts, sourceExts }, |
18 | | - transformer, |
19 | | - ...other |
20 | | - } = await getDefaultConfig(__dirname); |
21 | | - return { |
22 | | - ...other, |
23 | | - watchFolders, |
24 | | - transformer: { |
25 | | - ...transformer, |
26 | | - minifierConfig: { |
27 | | - keep_classnames: true, |
28 | | - // Need this for source mapping in @doc/pages to work. |
29 | | - keep_fnames: true, |
30 | | - mangle: { |
31 | | - keep_classnames: true, |
32 | | - // Need this for source mapping in @doc/pages to work. |
33 | | - keep_fnames: true |
34 | | - }, |
35 | | - output: { |
36 | | - ascii_only: true, |
37 | | - quote_style: 3, |
38 | | - wrap_iife: true |
39 | | - }, |
40 | | - sourceMap: { |
41 | | - includeSources: false |
42 | | - }, |
43 | | - toplevel: false, |
44 | | - compress: { |
45 | | - // reduce_funcs inlines single-use functions, which cause perf regressions. |
46 | | - reduce_funcs: false |
47 | | - } |
48 | | - }, |
49 | | - babelTransformerPath: require.resolve('react-native-svg-transformer') |
| 15 | +config.transformer = { |
| 16 | + ...config.transformer, |
| 17 | + minifierConfig: { |
| 18 | + keep_classnames: true, |
| 19 | + // Need this for source mapping in @doc/pages to work. |
| 20 | + keep_fnames: true, |
| 21 | + mangle: { |
| 22 | + keep_classnames: true, |
| 23 | + // Need this for source mapping in @doc/pages to work. |
| 24 | + keep_fnames: true |
50 | 25 | }, |
51 | | - resolver: { |
52 | | - assetExts: assetExts.filter((ext) => ext !== 'svg'), |
53 | | - sourceExts: [...sourceExts, 'svg'], |
54 | | - extraNodeModules: new Proxy( |
55 | | - {}, |
56 | | - { |
57 | | - get: (target, name) => path.join(__dirname, `node_modules/${name}`) |
58 | | - } |
59 | | - ) |
| 26 | + output: { |
| 27 | + ascii_only: true, |
| 28 | + quote_style: 3, |
| 29 | + wrap_iife: true |
| 30 | + }, |
| 31 | + sourceMap: { |
| 32 | + includeSources: false |
| 33 | + }, |
| 34 | + toplevel: false, |
| 35 | + compress: { |
| 36 | + // reduce_funcs inlines single-use functions, which cause perf regressions. |
| 37 | + reduce_funcs: false |
60 | 38 | } |
61 | | - }; |
62 | | -})(); |
| 39 | + }, |
| 40 | + babelTransformerPath: require.resolve('react-native-svg-transformer') |
| 41 | +}; |
| 42 | +config.resolver = { |
| 43 | + ...config.resolver, |
| 44 | + assetExts: config.resolver.assetExts.filter((ext) => ext !== 'svg'), |
| 45 | + sourceExts: [...config.resolver.sourceExts, 'svg'], |
| 46 | + nodeModulesPaths: [ |
| 47 | + ...config.resolver.nodeModulesPaths, |
| 48 | + ...packagesDirs.map((d) => |
| 49 | + path.resolve(packagesRoot, d, 'node_modules') |
| 50 | + ), |
| 51 | + ...docToolsDirs.map((d) => |
| 52 | + path.resolve(docToolsRoot, d, 'node_modules') |
| 53 | + ) |
| 54 | + ] |
| 55 | +}; |
| 56 | + |
| 57 | +module.exports = config; |
0 commit comments