forked from PIVX-Labs/MyPIVXWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
129 lines (124 loc) · 4.04 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
/* 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 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' });
const version = JSON.parse(
readFileSync('./package.json', { encoding: 'utf8' })
).version;
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: /\.svg$/i,
type: 'asset/source',
},
],
},
resolve: {
alias: {
'bn.js': path.join(__dirname, 'node_modules/bn.js/lib/bn.js'),
},
fallback: {
fs: false,
},
},
plugins: [
new HtmlWebpackPlugin({
template: './index.template.html',
filename: 'index.html',
favicon: './assets/favicon.ico',
meta: {
viewport:
'width=device-width, initial-scale=1, shrink-to-fit=no',
},
}),
new VueLoaderPlugin(),
// Polyfill for non web libraries
new NodePolyfillPlugin(),
// 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),
VERSION: JSON.stringify(version),
}),
// Ignore non english bip39 wordlists
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/wordlists\/(?!english)/,
contextRegExp: /bip39\/src$/,
}),
// 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' },
],
}),
],
};