-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
67 lines (66 loc) · 2.38 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
const path = require("path"); //connect plugin 'path'
const HTMLWebpackPlugin = require("html-webpack-plugin"); //connect htmlwebpackplugin
const { CleanWebpackPlugin } = require("clean-webpack-plugin"); //connect cleanwebpackplugin
const CopyWebpackPlugin = require("copy-webpack-plugin"); //connetct copewebpackplugin
module.exports = {
context: path.resolve(__dirname, "src"),
mode: "development", //mode
entry: {
//entry point
main: "./index.js", //for the main file
analytics: "./analytics.js", //analytics file
},
output: {
filename: "[name].[contenthash].js", //where to connect all javascript files - [name] => keys for the several files system
//[contenthash] - for the future, for cache — when user redirects to the page - need new file
//[] calls — pattern
path: path.resolve(__dirname, "dist"), //where to add all javascript files
},
resolve: {
extensions: [".js", ".json", ".css", ".png", ".xml"], //what extensions we should understand by default
alias: {
"@models": path.resolve(__dirname, "src/models"), //path to models
"@": path.resolve(__dirname, "src"),
},
},
optimization: {
splitChunks: {
chunks: "all", //connecting the same thing twice - put it in a separate file (vendors)
},
},
devServer: {
port: 4200, //live server's port
},
plugins: [
//all webpack plugins
new HTMLWebpackPlugin({
template: "./index.html", //path to the index.html
}),
new CleanWebpackPlugin(), //clean dist folder
new CopyWebpackPlugin({
patterns: [{
from: path.resolve(__dirname, "src/favicon.ico"), //copy file or folder from
to: path.resolve(__dirname, "dist"),
}, ],
}),
],
module: {
rules: [{
test: /\.css$/, //if webpack sees .css, it use 'use' rule
use: ["style-loader", "css-loader"],
},
{
test: /\.(png|jpg|svg|gif)$/,
use: ["file-loader"], // for use imgs
},
{
test: /\.(ttf|woff|woff2|eot)$/, //fonts
use: ["file-loader"],
},
{
test: /\.xml$/,
use: ["xml-loader"],
},
],
},
};