-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
128 lines (109 loc) · 4.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
// Enables the working for a path file
const path = require('path')
// this package handles all of the html files
const HtmlWebpackPlugin = require('html-webpack-plugin')
// a must, cleans the working directory before every new build
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
{
module.exports = {
// specify the src main js file
entry: {
src: ['./src/js/app.js'],
},
// where the main js file should go
output: {
path: path.resolve(__dirname, 'dist'),
filename: "js/bundle.js",
},
target: "web",
plugins: [
// from where to where, and specify minify options(optional and can be false)
new HtmlWebpackPlugin({
filename: "index.html",
template: "./src/index.html",
minify: {
collapseWhiteSpace: true,
collapseInlineTagWhiteSpace: true,
minifyCSS: true,
minifyJS: true,
minifyURLs:true,
removeComments: true,
}
}),
// If you wanna add more files, just add another HtmlWebpackPlugin object(like above)
// and associate it's options to the file that you want
new CleanWebpackPlugin()
],
// used for debugging in the browser and seeing error messages
// change it to "eval-cheap-module-source-map" once you don't need it
// it's better security to not allow anyone to access full source map
devtool: "source-map",
// setting up rules and loaders to handle different file types
module: {
rules: [
// babel for js files
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ['@babel/preset-env']
}
}
},
// first reads through scss files through sass-loader
// then processes them using postcss and autoprefixer inside of that
// then css files get handles by css loader and style loader attaches them to the js
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
'postcss-loader',
'sass-loader'
]
},
// handling all of the font files and putting them in dist/fonts
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: './fonts',
}
}
],
},
// handling all images and putting them in dist/img
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: './media',
}
},
],
},
// putting video files into the dist/media folder
{
test: /\.(mp4|webm)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: './media/',
}
},
],
},
]
}
}
}