forked from JSKitty/scc-web3
-
Notifications
You must be signed in to change notification settings - Fork 36
/
webpack.common.js
150 lines (145 loc) · 4.86 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
/* istanbul ignore file */
/* eslint-env node */
/* eslint @typescript-eslint/no-var-requires: "off" */
import path from 'path';
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import NodePolyfillPlugin from 'node-polyfill-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import CopyPlugin from 'copy-webpack-plugin';
import PreloadWebpackPlugin from '@vue/preload-webpack-plugin';
import toml from 'toml';
import { VueLoaderPlugin } from 'vue-loader';
import { readFileSync } from 'fs';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
// Inject the Changelog and Version to the app
const changelog = readFileSync('./changelog.md', { encoding: 'utf8' });
export default {
entry: './scripts/index.js',
output: {
path: path.resolve(__dirname, './dist'),
filename: './mpw.js',
library: 'MPW',
libraryTarget: 'var',
clean: true,
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.(jpe?g|png|gif|svg|mp3|svg)$/i,
type: 'asset/resource',
},
{
test: /\.vue/i,
use: {
loader: 'vue-loader',
options: {
compilerOptions: {
isCustomElement: (tag) => tag === 'center',
},
},
},
},
{
test: /\.toml$/,
// Json means we're returing an object.
// See https://webpack.js.org/configuration/module/#ruleparserparse
type: 'json',
parser: {
parse: (str) =>
toml.parse(
str
.split('\n')
// Ignore lines starting with ~~, it means we haven't
// translated them yet
.filter((l) => !l.match(/^[\w\s]+=\s*['"]~~/))
.join('\n')
),
},
},
{
test: /countries.json$/,
type: 'json',
parser: {
parse: (str) =>
JSON.parse(str).map((c) => {
return {
alpha2: c.alpha2,
currency: c.currency,
};
}),
},
},
{
test: /\.svg$/i,
type: 'asset/source',
},
],
},
resolve: {
fallback: {
fs: false,
crypto: path.resolve(__dirname, 'scripts/polyfills/crypto.js'),
},
},
plugins: [
new HtmlWebpackPlugin({
template: './index.template.html',
filename: 'index.html',
favicon: './assets/favicon.ico',
meta: {
viewport:
'width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no',
},
}),
new VueLoaderPlugin(),
// Polyfill for non web libraries
new NodePolyfillPlugin({
includeAliases: ['stream', 'process', 'Buffer'],
}),
// Prevents non styled flashing on load
new MiniCssExtractPlugin(),
// Make jquery available globally
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
}),
// Make the Changelog available globally
new webpack.DefinePlugin({
CHANGELOG: JSON.stringify(changelog),
}),
// Ignore non english bip39 wordlists
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/wordlists\/(?!english)/,
contextRegExp: /bip39\/src$/,
}),
// Ignore countries-intl
new webpack.IgnorePlugin({
resourceRegExp: /countries-intl.json$/,
}),
// Copy static web-facing files
new CopyPlugin({
patterns: [
{ from: 'manifest.json' },
{ from: 'assets/icons' },
{ from: 'assets/logo_opaque-dark-bg.png' },
{ from: 'scripts/native-worker.js' },
],
}),
new PreloadWebpackPlugin({
// This is something made up, it's just to get the
// bundle name in the service worker
rel: 'serviceworkprefetch',
include: 'all',
fileWhitelist: [/\.wasm$/, /(pivx-shield|util)/],
}),
],
};