-
Notifications
You must be signed in to change notification settings - Fork 608
/
index.js
139 lines (126 loc) Β· 3.77 KB
/
index.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
const TerminalReporter = require('metro/src/lib/TerminalReporter');
const blacklist = require('./blacklist');
const getMaxWorkers = require('metro/src/lib/getMaxWorkers');
const os = require('os');
const path = require('path');
const {
assetExts,
sourceExts,
platforms,
DEFAULT_METRO_MINIFIER_PATH,
defaultCreateModuleIdFactory,
} = require('./defaults');
const {FileStore} = require('metro-cache');
const {Terminal} = require('metro-core');
import type {ConfigT} from '../configTypes.flow';
const getDefaultValues = (projectRoot: ?string): ConfigT => ({
resolver: {
assetExts,
platforms,
sourceExts,
resolverMainFields: ['browser', 'main'],
extraNodeModules: {},
resolveRequest: null,
hasteImplModulePath: undefined,
blacklistRE: blacklist(),
useWatchman: true,
virtualMapper: file => [file],
},
serializer: {
polyfillModuleNames: [],
getRunModuleStatement: (moduleId: number | string) =>
`__r(${JSON.stringify(moduleId)});`,
getPolyfills: () => [],
postProcessBundleSourcemap: ({code, map, outFileName}) => ({code, map}),
getModulesRunBeforeMainModule: () => [],
processModuleFilter: module => true,
createModuleIdFactory: defaultCreateModuleIdFactory,
experimentalSerializerHook: () => {},
customSerializer: null,
},
server: {
useGlobalHotkey: true,
port: 8080,
enhanceMiddleware: middleware => middleware,
runInspectorProxy: true,
verifyConnections: false,
},
symbolicator: {
customizeFrame: () => {},
},
transformer: {
assetPlugins: [],
asyncRequireModulePath: 'metro/src/lib/bundle-modules/asyncRequire',
assetRegistryPath: 'missing-asset-registry-path',
babelTransformerPath: 'metro-babel-transformer',
dynamicDepsInPackages: 'throwAtRuntime',
enableBabelRCLookup: true,
enableBabelRuntime: true,
experimentalImportBundleSupport: false,
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
unstable_disableES6Transforms: false,
},
preloadedModules: false,
ramGroups: [],
}),
minifierConfig: {
mangle: {
toplevel: false,
},
output: {
ascii_only: true,
quote_style: 3,
wrap_iife: true,
},
sourceMap: {
includeSources: false,
},
toplevel: false,
compress: {
// reduce_funcs inlines single-use functions, which cause perf regressions.
reduce_funcs: false,
},
},
minifierPath: DEFAULT_METRO_MINIFIER_PATH,
optimizationSizeLimit: 150 * 1024, // 150 KiB.
postMinifyProcess: x => x,
transformVariants: {default: {}},
workerPath: 'metro/src/DeltaBundler/Worker',
publicPath: '/assets',
},
cacheStores: [
new FileStore({
root: path.join(os.tmpdir(), 'metro-cache'),
}),
],
cacheVersion: '1.0',
// We assume the default project path is two levels up from
// node_modules/metro/
projectRoot: projectRoot || path.resolve(__dirname, '../../..'),
stickyWorkers: true,
watchFolders: [],
transformerPath: require.resolve('metro/src/JSTransformer/worker.js'),
maxWorkers: getMaxWorkers(),
resetCache: false,
reporter: new TerminalReporter(new Terminal(process.stdout)),
});
async function getDefaultConfig(rootPath: ?string): Promise<ConfigT> {
// We can add more logic here to get a sensible default configuration, for
// now we just return a stub.
return getDefaultValues(rootPath);
}
module.exports = getDefaultConfig;
module.exports.getDefaultValues = getDefaultValues;