forked from CoinSpace/CoinSpace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
168 lines (165 loc) · 5.15 KB
/
webpack.common.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
const path = require('path');
const fs = require('fs/promises');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const webpack = require('webpack');
const pkg = require('./package.json');
const dotenv = require('dotenv');
const polyfills = ['core-js/stable', 'regenerator-runtime/runtime'];
const { RetryChunkLoadPlugin } = require('webpack-retry-chunk-load-plugin');
dotenv.config({ path: '.env.defaults' });
process.env.BUILD_TYPE = process.env.BUILD_TYPE || 'web';
const COMMIT = (
process.env.GITHUB_SHA ||
process.env.COMMIT_SHA ||
'local'
).substring(0, 7);
module.exports = {
// we should use web build for electron too
//target: process.env.BUILD_TYPE === 'electron' ? 'electron-renderer' : 'web',
target: ['web', 'es5'],
entry: {
loader: polyfills.concat('./app/loader/index.js'),
...(process.env.BUILD_TYPE === 'web' ? {
fido: polyfills.concat('./app/fido/index.js'),
} : {}),
},
output: {
filename: 'assets/js/[name].[fullhash:8].js',
chunkFilename: 'assets/js/[name].[fullhash:8].js',
path: path.resolve(__dirname, 'build'),
clean: true,
webassemblyModuleFilename: 'assets/wasm/[fullhash].module.wasm',
},
externals: {
electron: 'commonjs electron',
},
experiments: {
futureDefaults: true,
},
resolve: {
symlinks: false,
alias: {
lib: path.resolve(__dirname, 'app/lib'),
pages: path.resolve(__dirname, 'app/pages'),
widgets: path.resolve(__dirname, 'app/widgets'),
partials: path.resolve(__dirname, 'app/partials'),
},
fallback: {
assert: require.resolve('assert/'),
buffer: require.resolve('buffer/'),
events: require.resolve('events/'),
url: require.resolve('url/'),
querystring: require.resolve('querystring-es3'),
stream: require.resolve('stream-browserify'),
crypto: require.resolve('crypto-browserify'),
path: require.resolve('path-browserify'),
https: false,
http: false,
fs: false,
},
},
module: {
rules: [
{
test: /\.(png|svg|jpg|gif|ico|woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
generator: {
filename: (pathData) => {
let base = path.dirname(pathData.filename);
base = base.replace(/^app\//, '');
base = base.replace(/^node_modules\/@coinspace\/crypto-db\/logo/, 'assets/crypto');
return `${base}/[name].[hash:8][ext]`;
},
},
},
{
test: /MoneroCoreJS\.wasm$/i,
type: 'asset/resource',
generator: {
filename: 'assets/wasm/[name].[hash:8][ext]',
},
},
{
test: /\.ract$/,
use: ['ractive-loader'],
},
],
},
plugins: [
new HtmlWebpackPlugin({
chunks: ['loader'],
template: 'app/index.ejs',
}),
...(process.env.BUILD_TYPE === 'web' ?
[new HtmlWebpackPlugin({
chunks: ['fido'],
template: 'app/fido/index.ejs',
filename: 'fido/index.html',
}),
new CopyWebpackPlugin({
patterns: [{
from: 'node_modules/@coinspace/crypto-db/logo/',
to: './assets/crypto/',
}],
})] : []
),
...(process.env.BUILD_TYPE === 'electron' ?
[new CopyWebpackPlugin({
patterns: [{
from: 'node_modules/@coinspace/crypto-db/crypto/',
to: '../electron/lib/crypto/',
filter: async (resourcePath) => {
const data = JSON.parse(await fs.readFile(resourcePath, 'utf8'));
return !!data.scheme;
},
}],
})] : []
),
new CopyWebpackPlugin({
patterns: [
{ from: 'app/security.txt', to: './' },
{ from: 'app/assets/icons/android-chrome-192x192.png', to: './' },
{ from: 'app/assets/icons/android-chrome-512x512.png', to: './' },
{ from: 'app/assets/icons/apple-touch-icon.png', to: './' },
{ from: 'app/assets/icons/browserconfig.xml', to: './' },
{ from: 'app/assets/icons/favicon-16x16.png', to: './' },
{ from: 'app/assets/icons/favicon-32x32.png', to: './' },
{ from: 'app/assets/icons/favicon.ico', to: './' },
{ from: 'app/assets/icons/mstile-150x150.png', to: './' },
{ from: 'app/assets/icons/safari-pinned-tab.svg', to: './' },
{ from: 'app/assets/icons/site.webmanifest', to: './' },
],
}),
new CircularDependencyPlugin({
exclude: /node_modules/,
failOnError: true,
allowAsyncCycles: false,
cwd: process.cwd(),
}),
new webpack.ProvidePlugin({
Buffer: ['buffer/', 'Buffer'],
}),
new webpack.DefinePlugin({
'process.env.VERSION': JSON.stringify(`v${pkg.version}`),
'process.env.COMMIT': JSON.stringify(COMMIT),
}),
new RetryChunkLoadPlugin({
cacheBust: 'function() { return Date.now(); }',
retryDelay: 1000,
maxRetries: 3,
}),
],
optimization: {
splitChunks: false,
},
node: {
global: true,
__filename: 'mock',
__dirname: 'mock',
},
ignoreWarnings: [
{ module: /cardano_serialization_lib_bg.js/ },
],
};