-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
153 lines (144 loc) · 4.17 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
const CopyWebpackPlugin = require('copy-webpack-plugin');
const Dotenv = require('dotenv-webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const LodashWebpackPlugin = require('lodash-webpack-plugin')
const path = require('path')
const webpack = require('webpack')
// Port used to start ONLY the development environment
const port = process.env.PORT || 3005
const distDir = process.env.DIST_DIR || 'dist'
const dotEnvPath = process.env.DOT_ENV_PATH || './.env'
const dotEnv = new Dotenv({
path: path.resolve(__dirname, dotEnvPath),
})
module.exports = {
entry: './src/index.js',
devServer: {
historyApiFallback: true,
host: 'localhost',
open: true,
port,
},
devtool: 'inline-source-map',
// exclude: {
// test: [
// /\.html$/,
// /\.(js|jsx)$/,
// /\.css$/,
// /\.json$/,
// /\.bmp$/,
// /\.gif$/,
// /\.jpe?g$/,
// /\.png$/,
// ],
// exclude: [
// 'src/configs/configs/your.json'
// ]
// },
mode: 'development',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
esModule: false,
}
},
// {
// loader: 'style-loader'
// },
// {
// loader: 'css-loader',
// options: {
// modules: true,
// localsConvention: 'camelCase',
// sourceMap: true
// }
// }
]
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
use: [{
loader: 'url-loader?limit=100000',
}],
},
{
test: /\.(md)$/,
use: [{
loader: 'ignore-loader',
}]
},
]
},
output: {
filename: 'bundle.[fullhash].js',
path: path.resolve(__dirname, distDir),
},
plugins: [
// Copy static assets
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, 'public/images'),
to: 'images',
}
]
}),
/*
* Enables the use of process.env in the web browser
*/
dotEnv,
/*
* Configure plugin to automatically include hashed bundle filenames into the index.html file
*/
new HtmlWebpackPlugin({
template: 'public/index.html',
favicon: 'public/favicon.ico'
}),
/*
* Node modules to ignore while building
*/
...[
/abort-controller/,
/node-fetch/,
/node-localstorage/,
/nano/,
].map(regExp => new webpack.IgnorePlugin({ resourceRegExp: regExp })),
/*
* provide alternatives for NodeJS-only modules to be used in the web Browser
*/
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
'regeneratorRuntime': ['regenerator-runtime']
}),
/*
* Compress builds
*/
// excludes unsed lodash node_module features
new LodashWebpackPlugin(),
],
resolve: {
extensions: ['.js', '.jsx'],
fallback: {
assert: false,
// required by PolkadotJS
crypto: false,
fetch: false, // require.resolve('node-fetch')
FormData: false, //require.resolve('form-data'),
fs: false,
path: false,
stream: require.resolve('stream-browserify'),
util: false,
}
}
}