forked from franco-chan/OneKey-Desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect.webpack.js
114 lines (107 loc) · 3.5 KB
/
connect.webpack.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
/* eslint-disable @typescript-eslint/no-var-requires */
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const RemovePlugin = require('remove-files-webpack-plugin');
const path = require('path');
const SRC = 'node_modules/@onekeyhq/connect';
const DATA_SRC = `${SRC}/data`;
// iframe is not in npm, so we have its template in suite-data
const HTML_SRC = path.resolve(__dirname, 'iframe.html');
const DIST = path.resolve(__dirname, 'files/connect');
module.exports = {
mode: 'production',
entry: {
iframe: `./node_modules/@onekeyhq/connect/lib/iframe/iframe.js`,
},
output: {
filename: 'js/[name].[hash].js',
path: DIST,
publicPath: './',
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
],
},
resolve: {
modules: [SRC, 'node_modules'],
},
performance: {
hints: false,
},
plugins: [
new webpack.NormalModuleReplacementPlugin(/.blake2b$/, './blake2b.js'),
new webpack.NormalModuleReplacementPlugin(/env\/node$/, './env/browser'),
new webpack.NormalModuleReplacementPlugin(/env\/node\/workers$/, '../env/browser/workers'),
new webpack.NormalModuleReplacementPlugin(
/env\/node\/networkUtils$/,
'../env/browser/networkUtils',
),
new CopyWebpackPlugin({
patterns: [
{ from: DATA_SRC, to: `${DIST}/data` }, // only messages, coins, firmware releases
],
}),
// ignore Node.js lib from trezor-link
new webpack.IgnorePlugin(/\/iconv-loader$/),
new HtmlWebpackPlugin({
chunks: ['iframe'],
filename: 'iframe.html',
template: HTML_SRC,
minify: false,
inject: false,
}),
new RemovePlugin({
after: {
test: [
{
folder: `${DIST}/workers`,
method: filePath => {
return filePath.includes('shared-connection-worker.');
},
},
],
},
}),
],
// @trezor/utxo-lib NOTE:
// When uglifying the javascript, you must exclude the following variable names from being mangled:
// Array, BigInteger, Boolean, Buffer, ECPair, Function, Number, Point and Script.
// This is because of the function-name-duck-typing used in typeforce.
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
ecma: 6,
mangle: {
reserved: [
'Array',
'BigInteger',
'Boolean',
'Buffer',
'ECPair',
'Function',
'Number',
'Point',
'Script',
],
},
},
}),
],
},
// ignoring Node.js import in fastxpub (hd-wallet)
node: {
fs: 'empty',
path: 'empty',
net: 'empty',
tls: 'empty',
},
};