-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
168 lines (160 loc) · 5.07 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
process.traceDeprecation = true;
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const HtmlWebpackInlineSVGPlugin = require('html-webpack-inline-svg-plugin')
const nodeExternals = require('webpack-node-externals')
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'static/js/[name].[hash].js',
},
devServer: {
open: true,
compress: true,
port: 4000,
},
resolve: {
alias: {
mod: path.resolve(__dirname, 'node_modules/'),
}
},
// target: 'node',
// node: {
// __dirname: false,
// __filename: false
// },
// externals: [nodeExternals()], // Need this to avoid error when working with Express
/**
* Devtool SourceMaps
* dev - eval-source-map
* cheap-module-eval-source-map
* prod - source-map
* inline-source-map
*/
devtool: "source-map",
module: {
rules: [
{
test: /\.js$/,
include: path.resolve(__dirname, 'src'),
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.(sc|sa|c)ss$/,
exclude: /node_modules/,
use: [
'style-loader',
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true,
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
},
/* Image/Rasterized Asset Loader */
{
test: /\.(png|jpe?g|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'assets/images/',
publicPath: 'assets/images/',
}
}
]
},
/* SVG Loader
*
* [path] = relative to template url:
* e.g, if template is in src/public/index.html then [path] = src/public/
* [path] is prefixed to "name" to allow html template
* pre-parsing with inline-svg-plugin
*
* emitFile: false since we don't need to write/emit assets on the
* final build, we are handling that with inline-svg-plugin instead
**/
{
test: /\.svg$/,
use: [
{
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
emitFile: false
}
},
]
},
/* Font Loader */
{
test: /\.(woff|woff2|ttf|otf)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'assets/fonts/',
publicPath: 'assets/fonts/'
},
}
]
},
{
test: /\.(html)$/,
use: {
loader: 'html-loader',
options: {
minimize: true
}
}
}
]
},
plugins: [
new CleanWebpackPlugin('dist', {}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'src/public/index.html',
svgoConfig: {
removeTitle: false,
removeViewBox: true,
}
}),
new HtmlWebpackInlineSVGPlugin({
/**
* runPreEmit: true so it'll run "before" the html
* template is parsed by html-webpack-plugin
*/
runPreEmit: true,
}),
new MiniCssExtractPlugin({
filename: 'static/styles/[name].[contenthash].css',
chunkFilename: '[id].css'
}),
/* enable ONLY when HMR can be used for all assets - to test on UX part */
// new webpack.HotModuleReplacementPlugin()
]
}