-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.common.js
136 lines (127 loc) · 4.29 KB
/
webpack.common.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
const fs = require("fs");
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const WriteFilePlugin = require("write-file-webpack-plugin");
const FaviconsWebpackPlugin = require("favicons-webpack-plugin");
const imagemin = require("imagemin");
const imageminWebp = require("imagemin-webp");
//Returns full name of a first file in a given folder.
const returnFirstFile = folderPath =>
fs.readdirSync(folderPath)
.filter(item => !(/(^|\/)\.[^\/\.]/g)
.test(item))[0];
//Full favicon path
const faviconPath = "./assets/favicon/" +
returnFirstFile("./assets/favicon/");
(async () => {
const files = await imagemin(["./assets/images/common/*.{jpg,png}"], {
destination: "./assets/images/webp",
plugins: [imageminWebp({quality: 50})],
});
})();
module.exports = {
entry: {
main: "./src/index/scripts/index.js"
},
output: {
filename: "main.js",
path: path.resolve(__dirname, `dist`)
},
resolve: {
alias: {
IndexScripts: path.resolve(__dirname, `src/index/scripts`),
IndexComponents: path.resolve(__dirname, `src/index/scripts/components`),
IndexContainers: path.resolve(__dirname, `src/index/scripts/containers`),
IndexStyles: path.resolve(__dirname, `src/index/styles`),
Images: path.resolve(__dirname, `assets/images`)
}
},
devtool: "source-map",
module: {
rules: [
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{ //Enables class/id minimization & CSS modules
loader: "css-loader",
options: {
importLoaders: 2,
modules: {
localIdentName: "[sha1:hash:hex:4]"
}
}
},
"postcss-loader",
"sass-loader" // compiles Sass to CSS, using Node Sass by default
]
},
{
test: /\.(jpg|png|svg|jpeg|gif|webp)$/,
include: [
path.resolve(__dirname, "assets")
],
use: [
{
loader: "file-loader",
options: {
name: "[sha1:hash:hex:4].[ext]",
}
},
{
loader: "image-webpack-loader",
options: {
mozjpeg: {
progressive: true,
quality: 65
},
optipng: {
enabled: false,
},
pngquant: {
quality: [0.65, 0.90],
speed: 4
},
gifsicle: {
interlaced: false,
},
webp: {
quality: 75
}
}
}
]
}
],
},
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: "style.css"
}),
new OptimizeCSSAssetsPlugin({
assetNameRegExp: /\.css$/
}),
new FaviconsWebpackPlugin({
logo: faviconPath,
prefix: "icons/",
title: "Base Settings",
background: "#FFF",
icons: {
android: true,
appleIcon: true,
appleStartup: true,
coast: false,
favicons: true,
firefox: true,
opengraph: false,
twitter: false,
yandex: false,
windows: false
}
}),
],
};