-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
110 lines (109 loc) · 3.05 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
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
module.exports = (env, argv) => {
const devMode = argv.mode === "development";
return {
watch: devMode,
entry: {
main: "./source-src/js/main.js",
slider: "./source-src/js/slider.js",
mobile: ["babel-polyfill", "./source-src/js/mobile.js"],
},
output: {
path: __dirname + "/source",
publicPath: "",
filename: "[name].[chunkhash:7].js",
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
},
},
},
{
test: /\.(sa|sc|c)ss$/i,
use: [
devMode ? "style-loader" : MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
importLoaders: 2,
// 0 => no loaders (default);
// 1 => postcss-loader;
// 2 => postcss-loader, sass-loader
},
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
[
"postcss-import",
"postcss-preset-env",
"cssnano",
],
],
},
},
},
"sass-loader",
],
},
{
test: /\.(png|svg|jpe?g|gif|webp)$/i,
type: 'asset/resource',
generator: {
filename: 'images/[name].[hash:7][ext][query]'
},
},
{
test: /\.(woff|eot|ttf)$/i,
type: 'asset/resource',
generator: {
filename: 'fonts/[name].[hash:7][ext][query]'
},
},
{
test: /\.html$/i,
loader: "html",
},
],
},
plugins: [
// new CleanWebpackPlugin(["source/*"]),
new CleanWebpackPlugin({ verbose: true }),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: devMode ? "[name].css" : "[name].[chunkhash:7].css",
chunkFilename: devMode ? "[id].css" : "[id].[chunkhash:7].css",
}),
new HtmlWebpackPlugin({
inject: false,
cache: false,
template: "./source-src/css.ejs",
filename: "../layout/_partial/css.ejs",
}),
new HtmlWebpackPlugin({
inject: false,
cache: false,
template: "./source-src/script.ejs",
filename: "../layout/_partial/script.ejs",
}),
],
optimization: {
minimizer: [
new TerserPlugin({ extractComments: false }),
],
},
};
};