-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
161 lines (155 loc) · 4.04 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**
* Assets Config file
*/
const serverConfiguration = {
internal: {
server: {
baseDir: "docs",
},
port: 3000,
},
external: {
proxy: "http://localhost:9000/path/to/project/",
},
};
const path = require("path");
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const BrowserSyncPlugin = require("browser-sync-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ImageMinPlugin = require("imagemin-webpack-plugin").default;
let targetServerConfiguration = serverConfiguration.internal;
const config = function (env, args) {
if (args.externalServer !== undefined && args.externalServer) {
targetServerConfiguration = serverConfiguration.external;
}
return {
entry: {
app: "./src/js/app.js",
},
output: {
filename: "js/[name].js",
path: path.resolve(__dirname, "docs"),
},
module: {
rules: [
{
test: /\.scss$/,
use: [
"style-loader",
MiniCssExtractPlugin.loader,
"css-loader",
"postcss-loader",
"sass-loader",
],
},
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: "babel-loader",
},
{
test: /\.(png|gif|jpg|jpeg)$/,
use: [
{
loader: "url-loader",
options: {
name: "images/[name].[hash:6].[ext]",
publicPath: "../",
limit: 8192,
},
},
],
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
use: [
{
loader: "url-loader",
options: {
name: "fonts/[name].[hash:6].[ext]",
publicPath: "../",
limit: 8192,
},
},
],
},
// {
// test: /\.(svg)$/,
// use: [
// {
// loader: "url-loader",
// options: {
// name: "images/svg/[name].[ext]",
// publicPath: "../",
// limit: false,
// },
// },
// ],
// },
],
},
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
}),
new OptimizeCssAssetsPlugin({}),
],
},
watchOptions: {
poll: 1000,
ignored: /node_modules/,
},
plugins: [
new BrowserSyncPlugin({
...targetServerConfiguration,
files: ["src/*"],
ghostMode: {
clicks: false,
location: false,
forms: false,
scroll: false,
},
injectChanges: true,
logFileChanges: true,
logLevel: "debug",
logPrefix: "wepback",
notify: true,
reloadDelay: 0,
}),
new HtmlWebpackPlugin({
inject: true,
hash: false,
filename: "index.html",
template: path.resolve(__dirname, "src", "index.html"),
favicon: path.resolve(__dirname, "src", "images", "favicon.ico"),
}),
new MiniCssExtractPlugin({
filename: "css/[name].css",
}),
new ImageMinPlugin({ test: /\.(jpg|jpeg|png|gif)$/i }),
new CleanWebpackPlugin({
/**
* Some plugins used do not correctly save to webpack's asset list.
* Disable automatic asset cleaning until resolved
*/
cleanStaleWebpackAssets: false,
verbose: true,
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, "src", "images", ""),
to: path.resolve(__dirname, "docs", "images", ""),
toType: "dir",
},
],
}),
],
};
};
module.exports = config;