-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathwebpack.config.js
More file actions
132 lines (127 loc) · 3.55 KB
/
webpack.config.js
File metadata and controls
132 lines (127 loc) · 3.55 KB
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
const { exec } = require('child_process')
const path = require('path')
const CopyPlugin = require('copy-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const webpack = require('webpack')
// Use "yarn prepare.dev" to make a debug-friendly static build:
const debug =
process.env.WEBPACK_SERVE || process.env.EDGE_MODE === 'development'
// Try exposing our socket to adb (errors are fine):
if (process.env.WEBPACK_SERVE) {
console.log('adb reverse tcp:8080 tcp:8080')
exec('adb reverse tcp:8080 tcp:8080', () => {})
}
const bundlePath = path.resolve(
__dirname,
'android/src/main/assets/edge-core-js'
)
const babelOptions = {
presets: [
['@babel/preset-env', { targets: { chrome: '55' } }],
'@babel/preset-typescript',
'@babel/preset-react'
],
plugins: [
'@babel/plugin-transform-runtime',
'babel-plugin-transform-fake-error-class'
],
cacheDirectory: true
}
module.exports = {
devtool: debug ? 'source-map' : undefined,
devServer: {
allowedHosts: 'all',
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers':
'X-Requested-With, content-type, Authorization',
'Cross-Origin-Resource-Policy': 'cross-origin',
// Cross-origin isolation headers required for SharedArrayBuffer (needed by mixFetch web workers)
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp'
},
hot: false,
static: bundlePath
},
entry: './src/io/react-native/react-native-worker.ts',
experiments: {
asyncWebAssembly: true
},
mode: debug ? 'development' : 'production',
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: debug
? {
loader: '@sucrase/webpack-loader',
options: { transforms: ['typescript'] }
}
: {
loader: 'babel-loader',
options: babelOptions
}
},
{
include: path.resolve(__dirname, 'node_modules/buffer/index.js'),
use: {
loader: 'babel-loader',
options: { presets: ['@babel/preset-env'] }
}
},
{
test: /\.wasm$/,
type: 'webassembly/async'
}
]
},
optimization: {
minimizer: [new TerserPlugin({ terserOptions: { safari10: true } })]
},
output: {
filename: 'edge-core.js',
path: bundlePath
},
plugins: [
new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }),
new webpack.ProvidePlugin({ process: ['process'] }),
// Copy static files and mix-fetch WASM/worker files
new CopyPlugin({
patterns: [
// HTML entry point
{
from: path.resolve(__dirname, 'src/index.html'),
to: 'index.html'
},
// mix-fetch WASM files for NYM mixnet support
{
from: path.resolve(
__dirname,
'node_modules/@nymproject/mix-fetch/*.wasm'
),
to: '[name][ext]'
},
// mix-fetch web worker files
{
from: path.resolve(
__dirname,
'node_modules/@nymproject/mix-fetch/web-worker-*.js'
),
to: '[name][ext]'
}
]
})
],
performance: { hints: false },
resolve: {
extensions: ['.tsx', '.ts', '.js'],
fallback: {
assert: require.resolve('assert/'),
buffer: require.resolve('buffer/'),
stream: require.resolve('stream-browserify')
}
},
target: ['web', 'es5']
}