This repository was archived by the owner on Mar 11, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
90 lines (81 loc) · 2.23 KB
/
Copy pathwebpack.config.js
File metadata and controls
90 lines (81 loc) · 2.23 KB
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
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = {
// Входной файл
entry: ["./src/js/index.js"],
// Выходной файл
output: {
filename: "./js/bundle.js",
},
// Source maps для удобства отладки
devtool: "source-map",
module: {
rules: [
// Транспилируем js с babel
{
test: /\.js$/,
include: path.resolve(__dirname, "src/js"),
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
},
},
},
// Компилируем SCSS в CSS
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader, // Extract css to separate file
"css-loader", // translates CSS into CommonJS
"postcss-loader", // parse CSS and add vendor prefixes to CSS rules
"sass-loader", // compiles Sass to CSS, using Node Sass by default
],
},
// Подключаем шрифты из css
{
test: /\.(eot|ttf|woff|woff2)$/,
use: [
{
loader: "file-loader?name=./fonts/[name].[ext]",
},
],
},
// Подключаем картинки из css
{
test: /\.(svg|png|jpg|jpeg|webp)$/,
use: [
{
loader: "file-loader?name=./static/[name].[ext]",
},
],
},
],
},
plugins: [
// Подключаем файл html, стили и скрипты встроятся автоматически
new HtmlWebpackPlugin({
title: "Webpack 4 Starter",
template: "./src/index.html",
inject: true,
minify: {
removeComments: true,
collapseWhitespace: false,
},
}),
// Кладем стили в отдельный файлик
new MiniCssExtractPlugin({
filename: "style.css",
}),
// Копируем картинки
new CopyWebpackPlugin([
{
from: "./src/img",
to: "img",
},
]),
],
};