-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
147 lines (145 loc) · 3.86 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
const merge = require("webpack-merge");
const path = require("path");
const WorkboxPlugin = require("workbox-webpack-plugin");
const WebpackPwaManifest = require("webpack-pwa-manifest");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const RobotstxtPlugin = require("robotstxt-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const Visualizer = require("webpack-visualizer-plugin");
const { UnusedFilesWebpackPlugin } = require("unused-files-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const markdown = require("./webpack-config/module/markdown.js");
const htmlWebpackPlugin = require("./webpack-config/plugins/html-webpack-plugin.js");
const plugins = require("./webpack-config/plugins.js");
const config = {
mode: "production",
entry: "./src/index",
output: {
path: path.resolve(__dirname, "dist"),
publicPath: "/",
filename: "js/[name].bundle.js",
chunkFilename: "js/[name].bundle.js",
globalObject: "self"
},
module: {
rules: [
{
test: /\.(html)$/,
use: {
loader: "html-loader"
}
},
{
test: /\.css$/i,
use: ["to-string-loader", "css-loader"]
},
{
test: /\.tsx?$/,
use: "ts-loader"
}
]
},
resolve: {
extensions: [".js", ".ts"],
modules: ["vendor", "node_modules"],
alias: {
"lit-element": path.resolve("./node_modules/lit-element"),
"lit-html": path.resolve("./node_modules/lit-html")
}
},
devServer: {
// https: true,
compress: true,
contentBase: path.resolve(__dirname, "dist"),
open: true,
historyApiFallback: true
},
optimization: {
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
terserOptions: {
safari10: true
}
})
],
splitChunks: {
chunks: "async",
minSize: 30000,
maxSize: 0,
minChunks: 1,
maxAsyncRequests: 5,
maxInitialRequests: 3,
automaticNameDelimiter: "~",
name: true,
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
}
}
},
namedModules: true,
namedChunks: true
},
plugins: [
new CleanWebpackPlugin(["dist"]),
new WebpackPwaManifest({
filename: "manifest.json",
name: "Andrew Noblet",
short_name: "AN",
description: "Andrew Noblet",
background_color: "#000000",
crossorigin: "use-credentials", //can be null, use-credentials or anonymous
theme_color: "#000000",
icons: [
{
src: path.resolve("src/assets/icon.png"),
sizes: [96, 128, 192, 256, 384, 512] // multiple sizes
},
{
src: path.resolve("src/assets/large-icon.png"),
size: "1024x1024" // you can also use the specifications pattern
}
],
start_url: "/"
}),
new WorkboxPlugin.GenerateSW({
clientsClaim: true,
skipWaiting: true
}),
new CopyWebpackPlugin([
{
from: "node_modules/@webcomponents/webcomponentsjs/*",
to: "js/webcomponentsjs",
flatten: true
},
{
from: "src/assets/*",
to: "./",
flatten: true
},
{
from: "src/workers/**",
to: "./js/workers",
flatten: true
}
]),
new RobotstxtPlugin(),
new UnusedFilesWebpackPlugin({ patterns: ["src/**/*.*"] }),
new Visualizer()
],
externals: [
{
xmlhttprequest: "{XMLHttpRequest:XMLHttpRequest}"
}
]
};
module.exports = merge(config, plugins, markdown);