-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
173 lines (166 loc) · 4.88 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
173
const path = require('path');
const webpack = require('webpack');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const DefinePlugin = webpack.DefinePlugin;
module.exports = (env, args) => {
const isProduction = args.mode === 'production';
const isAnalyzer = isProduction && args.analyze;
const publicPath = isProduction ? '/' + (env && env.PUBLIC_PATH ? env.PUBLIC_PATH + '/' : '') : '/';
const config = {
entry: './src/index.js',
mode: 'development',
stats: {
assets: true,
children: false,
colors: true
},
output: {
path: path.resolve(__dirname, './dist'),
publicPath: publicPath,
filename: 'js/bundle.js?[contenthash]'
},
optimization: {
minimize: true,
removeEmptyChunks: true,
mergeDuplicateChunks: true,
flagIncludedChunks: true, // https://webpack.js.org/configuration/optimization/#optimizationflagincludedchunks
providedExports: true,
usedExports: 'global'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: [
[ '@babel/env', { targets: { browsers: [ 'last 2 versions' ] }, useBuiltIns: 'usage', corejs: 3, modules: false } ],
'@babel/react'
],
plugins: [
[ '@babel/transform-runtime', { corejs: 3 } ],
[ '@babel/plugin-proposal-class-properties']
]
}
},
{
test: /\.css$/,
use: [ MiniCssExtractPlugin.loader, 'css-loader' ]
},
{
test: /\.less$/,
use: [
{ loader: MiniCssExtractPlugin.loader },
{ loader: 'css-loader' },
{ loader: 'less-loader',
options: {
lessOptions: {
paths: [ path.resolve(__dirname, 'node_modules') ]
}
}
}
]
},
{
test: /-font\.js/,
use: [
{ loader: MiniCssExtractPlugin.loader },
{
loader: 'css-loader',
options: {
url: false
}
},
{
loader: 'webfonts-loader',
options: {
publicPath: '/bruga-weather/'
}
}
]
},
{
test: /\.(png|jpg|gif|svg)$/,
exclude: /(fa-.+\.svg)$/, /* Font Awesome */
loader: 'file-loader',
options: {
name: '[name].[ext]?[contenthash]',
outputPath: 'img'
}
},
{
test: [ /\.(woff|woff2|ttf|eot)$/, /(fa-.+\.svg)$/ ],
loader: 'file-loader',
options: {
name: '[name].[ext]?[contenthash]',
outputPath: 'fonts'
}
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader'
}
]
}
]
},
plugins: [
new DefinePlugin({
TIMEZONE_URL: JSON.stringify('https://bruga-time-zone.onrender.com/timezone'),
PUBLIC_PATH: publicPath
}),
new MiniCssExtractPlugin({
filename: 'styles/bundle.css?[contenthash]'
}),
new HtmlWebPackPlugin({
template: './src/index.html',
filename: './index.html',
favicon: './src/assets/logo.png', // TODO Delete when Favicon plugin is supported again
meta: {
viewport: 'user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no',
description: 'Simple weather app made with <3 by Andrés Brugarolas'
},
inject: true
})
// TODO new FaviconsWebpackPlugin('./src/assets/logo.png') // Webpack 5 still not supported
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src')
},
extensions: ['*', '.js', '.jsx', '.json']
},
devServer: {
static: {
directory: path.join(__dirname, 'dist')
},
compress: true,
port: 8080,
hot: true,
open: true,
allowedHosts: 'all' // for ngrok
},
performance: {
hints: false
},
devtool: 'eval-source-map'
};
if (isProduction) {
config.mode = 'production';
config.devtool = false;
console.log('publicPath', publicPath)
// Add babel-minify preset only in production
const babelRules = config.module.rules.find(rule => rule.loader === 'babel-loader');
babelRules.options.presets.unshift(['minify', { builtIns: true } ]);
}
if (isAnalyzer) {
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
config.plugins.push(new BundleAnalyzerPlugin());
}
return config;
}