-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
152 lines (144 loc) · 3.74 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const path = require('path');
const webpackPwaManifest = require("webpack-pwa-manifest");
const workboxPlugin = require("workbox-webpack-plugin");
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
const ImageminWebpackPlugin = require('imagemin-webp-webpack-plugin');
module.exports = {
entry: {
main: path.resolve(__dirname, 'src/scripts/index.ts'),
actSw: path.resolve(__dirname, "src/scripts/sw.ts"),
mainStyle: path.resolve(__dirname, "src/scripts/styles.ts"),
materialIcons: path.resolve(__dirname, 'src/scripts/materialicons.ts')
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'scripts/[name].js',
},
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: 'styles',
test: /\.css$/,
chunks: 'all',
enforce: true
}
}
}
},
module: {
rules: [
{
test:/\.css$/i,
use : [
'style-loader'
, 'css-loader']
},
{
test:/\.(sa|sc)ss$/i,
use : [
'style-loader'
, 'css-loader', {
loader: 'sass-loader',
options: {
implementation: require('sass'),
webpackImporter: false,
sassOptions: {
includePaths: ['./node_modules']
}
}
}]
},
{
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]',
}
}]
}
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src/templates/index.html'),
filename: 'index.html',
favicon: "./src/public/images/icons/restaurant-icon.svg",
minify: {
html5: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributese: true,
useShortDoctype: true
}
}),
new ScriptExtHtmlWebpackPlugin({
custom: {
test: /\.js$/,
attribute: 'crossorigin',
value: 'anonymous'
},
sync: ['main.js', 'mainStyle.js'],
defaultAttribute: 'async',
preload: {
test: /\.js$/
}
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, 'src/public/'),
to: path.resolve(__dirname, 'dist/'),
}
],
}),
new ImageminWebpackPlugin({
config: [
{
test: /\.(jpe?g|png)/,
options: {
quality: 26
}
}
],
overrideExtension: true
}),
new webpackPwaManifest({
name: "Favorite Restaurant",
short_name: "FavResto",
description: "Deliver a best Restaurant information for you!",
background_color: "#fff",
theme_color: "#d76700",
crossorigin: "use-credentials",
display: "standalone",
start_url: "/index.html",
scope: "/",
orientation: "any",
inject: true,
ios: true,
icons: [
{
src: path.resolve("src/public/images/icons/icon.png"),
sizes: [96, 128, 144, 192, 256, 384, 512],
purpose: "any maskable",
destination: "images/icons",
ios: true
}
]
}),
new workboxPlugin.InjectManifest({
swSrc: "./src/template-sw.js",
swDest: "service-worker.js"
})
],
};