-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.mjs
140 lines (134 loc) · 3.67 KB
/
webpack.config.mjs
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
140
import path from 'path';
import LavaMoat from '@lavamoat/webpack';
import fs from 'fs';
import TerserPlugin from 'terser-webpack-plugin';
import * as Repack from '@callstack/repack';
const loadJSON = (_path) => JSON.parse(fs.readFileSync(new URL(_path, import.meta.url)));
const appJson = loadJSON('./app.json');
export default (env) => {
const {
mode = 'development',
context = Repack.getDirname(import.meta.url),
entry = './index.js',
platform = process.env.PLATFORM,
minimize = mode === 'production',
devServer = undefined,
bundleFilename = 'index.bundle',
sourceMapFilename = 'index.bundle.map',
assetsPath = undefined,
reactNativePath = new URL('./node_modules/react-native', import.meta.url).pathname,
} = env;
const dirname = Repack.getDirname(import.meta.url);
if (!platform) {
throw new Error('Missing platform');
}
process.env.BABEL_ENV = mode;
return {
mode,
devtool: 'source-map',
context,
entry: [
...Repack.getInitializationEntries(reactNativePath, {
hmr: devServer && devServer.hmr,
}),
entry,
],
resolve: {
...Repack.getResolveOptions(platform),
alias: {
'react-native': reactNativePath,
'@babel/runtime': path.join(dirname, 'node_modules/@babel/runtime'),
},
},
output: {
path: path.join(dirname, 'build', platform),
publicPath: Repack.getPublicPath({ platform, devServer }),
filename: 'index.bundle',
},
optimization: {
minimize,
minimizer: [
new TerserPlugin({
test: /\.(js)?bundle(\?.*)?$/i,
extractComments: false,
terserOptions: {
format: {
comments: false,
},
},
}),
],
},
module: {
rules: [
{
test: /\.[jt]sx?$/,
include: [
/node_modules(.*[/\\])+react/,
/node_modules(.*[/\\])+@react-native/,
/node_modules(.*[/\\])+@react-navigation/,
/node_modules(.*[/\\])+@react-native-community/,
/node_modules(.*[/\\])+@expo/,
/node_modules(.*[/\\])+pretty-format/,
/node_modules(.*[/\\])+metro/,
/node_modules(.*[/\\])+abort-controller/,
/node_modules(.*[/\\])+@callstack\/repack/,
],
use: 'babel-loader',
},
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
plugins: devServer && devServer.hmr ? ['module:react-refresh/babel'] : undefined,
},
},
},
{
test: Repack.getAssetExtensionsRegExp(Repack.ASSET_EXTENSIONS.filter((ext) => ext !== 'svg')),
use: {
loader: '@callstack/repack/assets-loader',
options: {
platform,
devServerEnabled: Boolean(devServer),
scalableAssetExtensions: Repack.SCALABLE_ASSETS,
},
},
},
{
test: /\.svg$/,
use: [
{
loader: '@svgr/webpack',
options: {
native: true,
dimensions: false,
},
},
],
},
],
},
plugins: [
new Repack.RepackPlugin({
context,
mode,
platform,
devServer,
output: {
bundleFilename,
sourceMapFilename,
assetsPath,
},
}),
new LavaMoat({
generatePolicy: true,
readableResourceIds: true,
diagnosticsVerbosity: 1,
// HtmlWebpackPluginInterop: true,
}),
],
};
};