This repository has been archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
/
webpack.config.js
172 lines (165 loc) · 3.98 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
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
169
170
171
172
require('dotenv').config()
const path = require('path')
const webpack = require('webpack')
const SriPlugin = require('webpack-subresource-integrity')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const isProduction = process.env.NODE_ENV === 'production'
let devtool = 'cheap-module-source-map'
if (isProduction) {
devtool = false
}
const webpackConfig = {
entry: {
app: './src/index.js'
},
devtool,
output: {
filename: '[name].js',
chunkFilename: '[name].[hash:8].bundle.js',
path: path.resolve(__dirname, 'build'),
crossOriginLoading: 'anonymous'
},
externals: {
Web3: 'web3'
},
module: {
noParse: [/^react$/],
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto'
},
{
test: /\.svg$/,
issuer: /\.jsx?$/,
use: [
{
loader: 'babel-loader'
},
{
loader: 'react-svg-loader',
options: {
jsx: true // true outputs JSX tags
}
}
]
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: 'file-loader'
}
]
},
{
test: /\.svg$/,
issuer: /\.s?css$/,
use: [
{
loader: 'file-loader'
}
]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[hash].[ext]',
},
}
]
},
{
test: /\.(scss|sass|css)$/i,
use: [
// Creates `style` nodes from JS strings
'style-loader',
// Translates CSS into CommonJS
{
loader: 'css-loader',
},
'resolve-url-loader',
// Compiles Sass to CSS
'sass-loader',
],
},
]
},
resolve: {
extensions: ['.js', '.json'],
modules: [path.resolve(__dirname, 'src/constants'), './node_modules'],
symlinks: false
},
node: {
fs: 'empty'
},
devServer: {
port: process.env.PORT || 3000,
host: '0.0.0.0',
headers: {
'Access-Control-Allow-Origin': '*'
},
contentBase: [
path.join(__dirname, 'public'),
path.join(__dirname, 'src/css')
]
},
mode: isProduction ? 'production' : 'development',
plugins: [
new SriPlugin({
hashFuncNames: ['sha256', 'sha384'],
enabled: isProduction
}),
new HtmlWebpackPlugin({
template: 'public/index.html',
inject: true
}),
new webpack.EnvironmentPlugin({
WEBPACK_BUILD: true,
NODE_ENV: process.env.NODE_ENV || 'development',
CLIENT_SENTRY_DSN: process.env.CLIENT_SENTRY_DSN || '',
TEAM_API_URL: process.env.TEAM_API_URL || 'http://localhost:5000',
API_URL: process.env.API_URL || 'http://localhost:5000',
ENABLE_GA: process.env.ENABLE_GA || false,
INVESTOR_API_URL: process.env.INVESTOR_API_URL || 'http://localhost:5000'
})
],
optimization: {
splitChunks: {
chunks: 'all'
}
}
}
if (isProduction) {
webpackConfig.output.filename = '[name].[hash:8].js'
webpackConfig.optimization.minimizer = [
new TerserPlugin({ extractComments: false }),
new OptimizeCSSAssetsPlugin({})
]
webpackConfig.plugins.push(
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [
'app.*.css',
'app.*.js',
'app.*.js.map',
'vendors*',
'dist/*.bundle.js'
]
}),
new MiniCssExtractPlugin({ filename: '[name].[hash:8].css' })
)
}
module.exports = webpackConfig