forked from BlockchainZoo/keyhub-vault
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
135 lines (131 loc) · 3.72 KB
/
webpack.config.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
'use strict'
const path = require('path')
const { fork } = require('child_process')
// eslint-disable-next-line import/no-extraneous-dependencies
const webpack = require('webpack')
// eslint-disable-next-line import/no-extraneous-dependencies
const CopyWebpackPlugin = require('copy-webpack-plugin')
module.exports = env => ({
mode: 'production',
devtool: 'cheap-source-map',
optimization: {
minimize: false,
},
entry: {
// 'whatwg-fetch': 'whatwg-fetch',
// 'abortcontroller-polyfill': 'abortcontroller-polyfill/dist/polyfill-patch-fetch',
main: './src/main.js',
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist', 'js'),
publicPath: '/js/',
},
plugins: [
// new webpack.SourceMapDevToolPlugin({
// filename: '[file].map',
// publicPath: 'https://localhost:5500/js/',
// fileContext: '',
// }),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
APP_ENV: JSON.stringify('browser'),
STAGE: JSON.stringify(env.STAGE || 'sandbox'),
},
}),
{
// Run a script after compilation
apply: compiler =>
compiler.hooks.afterEmit.tap('AfterEmitPlugin', compilation => {
process.stdout.write(`FullHash: ${compilation.fullHash}\n`)
const opts = {
env: { CODESIGN_PASSPHRASE: env.CODESIGN_PASSPHRASE },
silent: true,
}
const child = fork('build/openpgp.sign.js', ['./dist/js/main.bundle.js'], opts)
// const child = spawn('node', ['build/openpgp.sign.js', './dist/js/main.bundle.js'])
child.stdout.on('data', data => process.stdout.write(data))
child.stderr.on('data', data => process.stderr.write(data))
}),
},
new CopyWebpackPlugin(
[
{
from: path.resolve(__dirname, 'public/'),
to: path.resolve(__dirname, 'dist/'),
force: true,
},
],
{
ignore: ['*.bak', '*.bak.html'],
}
),
],
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
// See: https://medium.com/@zural143/basic-webpack-4-and-es5-to-es6-transpiler-using-babel-dc66e72c86c6
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: '> 5%, last 2 versions, Firefox ESR, not dead',
},
],
],
plugins: ['@babel/plugin-proposal-object-rest-spread'],
},
},
},
{
test: /\.worker\.js$/,
exclude: /(node_modules|bower_components)/,
use: [
{
loader: 'worker-loader',
options: { inline: true, fallback: false },
},
{
// See: https://medium.com/@zural143/basic-webpack-4-and-es5-to-es6-transpiler-using-babel-dc66e72c86c6
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: '> 5%, last 2 versions, Firefox ESR, not dead',
},
],
],
plugins: ['@babel/plugin-proposal-object-rest-spread'],
},
},
],
},
],
},
// externals: {
// jquery: 'jQuery',
// jsdom: 'jsdom',
// 'node-fetch': {
// commonjs: 'node-fetch',
// amd: 'node-fetch',
// root: 'fetch',
// },
// },
node: {
console: false,
global: true,
process: 'mock',
__filename: false,
__dirname: false,
Buffer: 'mock',
setImmediate: false,
},
})