This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.js
106 lines (102 loc) · 3.5 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
const path = require("path"),
ExtractTextPlugin = require("extract-text-webpack-plugin"),
UglifyJsPlugin = require("uglifyjs-webpack-plugin"),
CopyWebpackPlugin = require("copy-webpack-plugin"),
CleanWebpackPlugin = require("clean-webpack-plugin"),
webpack = require("webpack");
const plugins = [
new ExtractTextPlugin("styles/[name]-bundle.css"),
new CopyWebpackPlugin([
{
from: "./src/images/",
to: "",
ignore: ["icons/*"],
},
]),
],
cssOptions = {
importLoaders: 1,
};
module.exports = (env, argv) => {
if (argv.mode === "production") {
plugins.push(
new UglifyJsPlugin({
test: /\.js($|\?)/i,
exclude: /(node_modules)/,
}),
new CleanWebpackPlugin("assets/*", {
root: __dirname,
})
);
cssOptions.minimize = true;
}
return {
entry: {
home: path.resolve(__dirname, "./src/pages/Home/Home.js"),
blog: path.resolve(__dirname, "./src/pages/Blog/Blog.js"),
bit: path.resolve(__dirname, "./src/pages/Bit/Bit.js"),
video: path.resolve(__dirname, "./src/pages/Video/Video.js"),
post: path.resolve(__dirname, "./src/pages/Post/Post.js"),
postbit: path.resolve(__dirname, "./src/pages/PostBit/PostBit.js"),
singlepage: path.resolve(
__dirname,
"./src/pages/SinglePage/SinglePage.js"
),
author: path.resolve(__dirname, "./src/pages/Author/Author.js"),
tag: path.resolve(__dirname, "./src/pages/Tag/Tag.js"),
},
output: {
path: path.resolve(__dirname, "assets"),
filename: "js/[name]-bundle.js",
publicPath: "./assets/",
},
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: [
{
loader: "css-loader",
options: cssOptions,
},
"postcss-loader",
],
}),
},
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: "babel-loader",
options: { presets: ["@babel/preset-env"] },
},
},
{
test: /\.(jpg|png|gif)$/,
use: {
loader: "url-loader",
options: {
limit: 100000,
fallback: "file-loader",
name: "images/[name].[ext]",
},
},
},
{
test: /\.(woff|eot|ttf|svg)$/,
use: {
loader: "url-loader",
options: {
limit: 100000,
fallback: "file-loader",
name: "fonts/[name].[ext]",
},
},
},
],
},
plugins: plugins,
optimization: { splitChunks: { name: "common", chunks: "initial" } },
};
};