-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.js
executable file
·248 lines (228 loc) · 6.99 KB
/
webpack.prod.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
const path = require("path");
const glob = require("glob");
const PATHS = {
src: path.join(__dirname, "src"),
};
const WebpackBar = require("webpackbar");
const webpack = require("webpack");
const autoprefixer = require("autoprefixer");
const htmlWebpackPlugin = require("html-webpack-plugin");
const miniCssExtractPlugin = require("mini-css-extract-plugin");
const optimizeCss = require("optimize-css-assets-webpack-plugin");
const terser = require("terser-webpack-plugin");
const PurgecssPlugin = require("purgecss-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const WebpackPwaManifest = require("webpack-pwa-manifest");
const manifestConfig = {
// Your source logo
logo: "./src/images/icons/icon-512x512.png",
// Output path for icons (icons will be saved to output.path(webpack config) + this key)
output: "icons//", // default '/'. Can be absolute or relative
// Generate a cache file with control hashes and
// don't rebuild the favicons until those hashes change
persistentCache: true,
// Inject the html into the html-webpack-plugin. Default true
inject: true,
// favicons configuration object. Support all keys of favicons (see https://github.com/haydenbleasel/favicons)
config: {
// Your application's name. `string`
appName: "PWA Camera",
// Your application's description. `string`
appDescription: "test",
// Your (or your developer's) name. `string`
developerName: null,
// Your (or your developer's) URL. `string`
developerURL: null,
// Background colour for flattened icons. `string`
background: "#fff",
// Theme color for browser chrome. `string`
theme_color: "#1e88e5",
// Android display: "browser" or "standalone". `string`
display: "standalone",
// Android orientation: "portrait" or "landscape". `string`
orientation: "portrait",
// Android start application's URL. `string`
start_url: "/?homescreen=1",
// Your application's version number. `number`
version: "1.0",
icons: {
// Create Android homescreen icon. `boolean` or `{ offset, background, shadow }`
android: true,
// Create Apple touch icons. `boolean` or `{ offset, background }`
appleIcon: true,
// Create Apple startup images. `boolean` or `{ offset, background }`
appleStartup: true,
coast: {
// Create Opera Coast icon with offset 25%. `boolean` or `{ offset, background }`
offset: 25,
},
// Create regular favicons. `boolean`
favicons: false,
// Create Firefox OS icons. `boolean` or `{ offset, background }`
firefox: true,
// Create Windows 8 tile icons. `boolean` or `{ background }`
windows: true,
// Create Yandex browser icon. `boolean` or `{ background }`
yandex: true,
},
},
};
const WorkboxPlugin = require("workbox-webpack-plugin");
module.exports = {
mode: "production",
entry: {
indexEn: "./src/js/en/index.ts",
aboutEn: "./src/js/en/about.ts",
productsEn: "./src/js/en/products.ts",
contactEn: "./src/js/en/contact.ts",
errorEn: "./src/js/en/error.ts",
},
output: {
filename: "[name].[hash].js",
path: path.resolve(__dirname, "build"),
publicPath: "/",
},
resolve: {
extensions: ['.js', '.ts', '.json'],
},
optimization: {
minimizer: [new terser(), new optimizeCss()],
},
module: {
rules: [
{
test: /\.(html)$/,
use: {
loader: "html-loader-srcset",
options: {
attrs: [":data-lazy", ":srcset", ":source", ":src", ":href"],
},
},
},
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.json$/,
use: ["json-loader"],
type: "javascript/auto",
},
{
test: /\.css$/,
use: [miniCssExtractPlugin.loader, "css-loader", "postcss-loader"],
},
{
test: /\.scss$/,
use: [miniCssExtractPlugin.loader, "css-loader", "postcss-loader", "sass-loader"],
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
plugins: [],
},
},
},
{
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "fonts",
},
},
],
},
{
test: /\.(svg|png|jpe?g|ico|webp)$/,
use: {
loader: "file-loader",
options: {
name: "[name].[hash].[ext]",
outputPath: "img",
},
},
},
],
},
plugins: [
new CleanWebpackPlugin(),
new WebpackBar({}),
new webpack.LoaderOptionsPlugin({
options: {
postcss: [autoprefixer()],
},
}),
new WebpackPwaManifest({
name: "My Progressive Web App",
short_name: "MyPWA",
description: "My awesome Progressive Web App!",
background_color: "#ffffff",
//can be null, use-credentials or anonymous
crossorigin: "use-credentials",
icons: [
{
src: path.resolve("src/images/icons/icon-512x512.png"),
// multiple sizes
sizes: [96, 128, 192, 256, 384, 512],
},
],
}),
new miniCssExtractPlugin({
filename: "[name].[hash]..css",
}),
/**
|--------------------------------------------------
| PRODUCTION
|
| Create english content
|--------------------------------------------------
*/
new htmlWebpackPlugin({
title: "index",
filename: "index.html",
template: "./src/pages/en/index.html",
chunks: ["indexEn"],
}),
new htmlWebpackPlugin({
title: "about",
filename: "en/about.html",
template: "./src/pages/en/about.html",
chunks: ["aboutEn"],
}),
new htmlWebpackPlugin({
title: "products",
filename: "en/products.html",
template: "./src/pages/en/products.html",
chunks: ["productsEn"],
}),
new htmlWebpackPlugin({
title: "contact",
filename: "en/contact.html",
template: "./src/pages/en/contact.html",
chunks: ["contactEn"],
}),
new htmlWebpackPlugin({
title: "error",
filename: "en/error.html",
template: "./src/pages/en/error.html",
chunks: ["errorEn"],
}),
new WorkboxPlugin.GenerateSW({
// these options encourage the ServiceWorkers to get in there fast
// and not allow any straggling "old" SWs to hang around
clientsClaim: true,
skipWaiting: true,
}),
],
};
//new PurgecssPlugin({
// paths: glob.sync(`${PATHS.src}/**/*`, { nodir: true })
//})