/
webpack.config.js
78 lines (71 loc) · 2.24 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
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
const path = require("path");
const threadLoader = require("thread-loader");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const jsWorkerCommonOptions = {
workers: 2,
workerParallelJobs: 50,
poolParallelJobs: 50
};
const babelWorkerOptions = {
...jsWorkerCommonOptions,
name: "babel-pool"
};
const tsWorkerOptions = {
...jsWorkerCommonOptions,
name: "ts-pool"
};
module.exports = ({ config, mode }) => {
if (mode !== "PRODUCTION") {
threadLoader.warmup(babelWorkerOptions, ["babel-loader"]);
threadLoader.warmup(tsWorkerOptions, ["babel-loader"]);
}
config.module.rules.push({
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{ loader: "cache-loader" },
{ loader: "thread-loader", options: tsWorkerOptions },
{
loader: "babel-loader",
options: {
presets: ["@babel/preset-typescript"]
}
}
]
});
config.module.rules.push({
test: /\.jsx?$/,
include: [
path.resolve(__dirname, "../node_modules/react-native"),
path.resolve(__dirname, "../node_modules/react-native-paper"),
path.resolve(__dirname, "../node_modules/react-native-elements"),
path.resolve(__dirname, "../node_modules/react-native-safe-area-view"),
path.resolve(__dirname, "../node_modules/react-native-vector-icons"),
path.resolve(__dirname, "../node_modules/@expo/vector-icons"),
path.resolve(__dirname, "../node_modules/react-native-ratings"),
path.resolve(__dirname, "../node_modules/react-native-status-bar-height")
],
use: [
{ loader: "cache-loader" },
{ loader: "thread-loader", options: babelWorkerOptions },
{
loader: "babel-loader?cacheDirectory?true",
options: {
presets: [
"module:metro-react-native-babel-preset",
"@babel/preset-flow"
]
}
}
]
});
// convert react-native to react-native-web for storybook
config.resolve.alias["react-native$"] = require.resolve("react-native-web");
config.resolve.alias["@expo/vector-icons"] = path.resolve(
__dirname,
"../node_modules/react-native-vector-icons"
);
// inlcude .ts and .tsx files
config.resolve.extensions.push(".ts", ".tsx");
return config;
};