forked from envelopetech/xpowebpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
133 lines (130 loc) · 3.45 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
var webpack = require('webpack');
var path = require("path");
var srcPath = path.resolve(__dirname, "src");
var distPath = path.resolve(__dirname, "build");
const HtmlWebPackPlugin = require("html-webpack-plugin");
var ManifestPlugin = require('webpack-manifest-plugin');
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
const CompressionPlugin = require('compression-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const Dotenv = require('dotenv-webpack');
var publicUrl = './public';
var config = {
devtool: 'source-map',
entry: [
srcPath + "/index.js"
],
output: {
path: distPath,
publicPath: '/',
filename: "bundle.js",
chunkFilename: "chunk.js"
},
plugins: [
new Dotenv({
path: './.env', // load this now instead of the ones in '.env'
safe: true, // load '.env.example' to verify the '.env' variables are all set. Can also be a string to a different file.
allowEmptyValues: true, // allow empty variables (e.g. `FOO=`) (treat it as empty string, rather than missing)
systemvars: true, // load all the predefined 'process.env' variables which will trump anything local per dotenv specs.
silent: true, // hide any errors
defaults: false // load '.env.defaults' as the default values if empty.
}),
new MiniCssExtractPlugin({
filename: "[name].[hash].css",
chunkFilename: "[id].[hash].css",
}),
new HtmlWebPackPlugin({
cache: true,
template: "public/index.html",
favicon: 'public/favicon_io/favicon.ico'
}),
new ManifestPlugin(),
new InterpolateHtmlPlugin(HtmlWebPackPlugin, {
PUBLIC_URL: publicUrl,
// You can pass any key-value pairs, this was just an example.
// WHATEVER: 42 will replace %WHATEVER% with 42 in index.html.
}),
new CompressionPlugin({
filename: '[path].gz[query]',
test: /\.js(\?.*)?$/i,
algorithm: 'gzip',
threshold: 10240,
minRatio: 0.8,
cache: true
})
],
resolve: {
extensions: ['.js', '.jsx']
},
module: {
rules: [
{
test: /\.js?$/,
exclude: /node_modules/,
include: /src/,
loader: "babel-loader",
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
include: /src/,
loader: "babel-loader",
},
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
loader: require.resolve('url-loader'),
options: {
limit: 10000,
name: 'static/media/[name].[hash:8].[ext]',
},
},
{
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: true
}
}
],
include: /\.module\.css$/
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
],
exclude: /\.module\.css$/
},
{
test: /\.html$/,
use: [
{
loader: "html-loader"
}
]
},
{
test: /\.svg$/,
use: ['@svgr/webpack', 'url-loader'],
},
{
test: /\.ico$/,
loader: "url-loader",
query: { mimetype: "image/x-icon" }
}
]
},
devServer: {
historyApiFallback: true,
contentBase: './',
hot: true,
port: 4500,
writeToDisk: true,
}
}
module.exports = config;