-
Notifications
You must be signed in to change notification settings - Fork 57
/
webpack.config.js
169 lines (143 loc) · 3.64 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
162
163
164
165
166
167
168
169
"use strict";
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const WebpackPwaManifest = require("webpack-pwa-manifest");
const WorkboxPlugin = require("workbox-webpack-plugin");
const isDev = process.env["NODE_ENV"] === "development";
const root = path.resolve(__dirname);
const PATHS = {
appPackageJson: path.resolve(root, "package.json"),
appSrc: path.resolve(root, "./src"),
appDist: path.resolve(root, "./dist"),
nodeModules: path.resolve(root, "./node_modules"),
changelog: path.resolve(root, "./CHANGELOG.md")
};
const { friendlyName, description } = require(PATHS.appPackageJson);
const PUBLIC_URL_PATH = "/oni-duplicity/";
console.log("Webpack build", isDev ? "[development]" : "[production]");
module.exports = {
mode: isDev ? "development" : "production",
devtool: "source-map",
devServer: {
contentBase: PATHS.appDist,
hot: isDev,
historyApiFallback: true
},
entry: {
client: [path.join(PATHS.appSrc, "./index.tsx")]
},
output: {
filename: "[name].[hash].bundle.js",
path: PATHS.appBuild,
publicPath: isDev ? "/" : PUBLIC_URL_PATH,
// Fix hot-reload interfering with worker-loader
globalObject: "this"
},
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx", ".js", ".json"],
alias: {
"@": PATHS.appSrc,
"@changelog": PATHS.changelog
}
},
module: {
rules: [
// Process source maps in input sources
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
enforce: "pre",
test: /\.(jsx?|tsx?)$/,
loader: "source-map-loader",
include: [/src\/.+\.tsx?/]
},
{
test: /\.tsx?$/,
use: [
{
loader: "ts-loader"
}
]
},
{
test: /\.css$/,
loader: ["style-loader", "css-loader"]
},
{
test: /\.(woff|woff2)$/,
use: {
loader: "url-loader",
options: {
name: "fonts/[hash].[ext]",
limit: 5000,
mimetype: "application/font-woff"
}
}
},
{
test: /\.(ttf|eot|svg)$/,
use: {
loader: "file-loader",
options: {
name: "fonts/[hash].[ext]"
}
}
},
{
test: /\.png/,
loader: "file-loader",
options: {
name: "images/[hash].[ext]"
}
},
{
test: /\.(txt|md)$/,
loader: "raw-loader"
}
]
},
plugins: [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(isDev ? "development" : "production")
}
}),
new HtmlWebpackPlugin({
inject: true,
template: path.resolve(PATHS.appSrc, "index.ejs")
}),
new WebpackPwaManifest({
name: `${friendlyName}: ${description}`,
short_name: friendlyName,
description,
background_color: "#000000",
crossorigin: null,
display: "standalone",
inject: true
}),
new WorkboxPlugin.GenerateSW({
clientsClaim: true,
skipWaiting: true
})
],
optimization: {
runtimeChunk: true,
splitChunks: {
chunks: "all",
cacheGroups: {
npm: {
test: /node_modules/,
name: mod => {
const relToModule = path.relative(PATHS.nodeModules, mod.context);
const moduleName = relToModule.substring(
0,
relToModule.indexOf(path.sep)
);
return `npm.${moduleName}`;
}
}
}
}
}
};