forked from Smuzzies/seevechain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
executable file
·126 lines (121 loc) · 3.2 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
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const Dotenv = require('dotenv-webpack')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const webpack = require('webpack')
const ROOT = path.resolve(__dirname, '.')
const srcPath = `${ROOT}/client`
const outputPath = `${ROOT}/client/dist`
const production = process.env.NODE_ENV === 'production'
const config = {
devtool: production ? undefined : 'sourcemap',
mode: process.env.NODE_ENV || 'development',
stats: {
assets: true,
warnings: true,
children: false,
depth: false,
entrypoints: false,
errors: true,
errorDetails: true,
hash: false,
},
entry: ['@babel/polyfill', `${srcPath}/index.js`],
output: {
path: outputPath,
filename: '[name].bundle.js',
publicPath: '/',
},
context: srcPath,
resolve: {
alias: {
react: 'preact/compat',
'react-dom': 'preact/compat',
components: `${srcPath}/components`,
assets: `${srcPath}/assets`,
lib: `${srcPath}/lib`,
},
},
module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /(node_modules)/,
},
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
]
},
{
test: /\.(ico|jpg|jpeg|png|gif|otf|webp)(\?.*)?$/,
loader: 'file-loader',
query: {
name: 'assets/[name].[ext]'
}
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader',
query: {
name: 'assets/[name].[ext]'
}
},
{
test: /\.mp3$/,
loader: 'file-loader',
},
],
},
plugins: [
new HtmlWebpackPlugin({
title: 'See Vechain',
inject: true,
template: `${srcPath}/index.ejs`,
favicon: `${srcPath}/assets/favicon.ico`,
minify: {
removeComments: production,
collapseWhitespace: production,
removeRedundantAttributes: production,
useShortDoctype: production,
removeEmptyAttributes: production,
removeStyleLinkTypeAttributes: production,
keepClosingSlash: production,
minifyJS: production,
minifyCSS: production,
minifyURLs: production,
},
meta: {
description: 'Real-time visualizer of the VeChain blockchain',
},
cache: false,
}),
new MiniCssExtractPlugin({
filename: production ? '[name].[hash].css' : '[name].css',
chunkFilename: production ? '[id].[hash].css' :'[id].css',
}),
new CleanWebpackPlugin(),
new Dotenv(),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// new BundleAnalyzerPlugin(),
],
}
if (production) {
config.plugins.push(
new CompressionPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: /\.(js|css)$/,
threshold: 10240,
minRatio: 0.7,
})
)
}
module.exports = config