-
Notifications
You must be signed in to change notification settings - Fork 27
/
webpack-production.config.js
140 lines (135 loc) · 3.92 KB
/
webpack-production.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
require("dotenv").config();
const webpack = require("webpack");
const path = require("path");
const buildPath = path.resolve(__dirname, "build");
const nodeModulesPath = path.resolve(__dirname, "node_modules");
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const WorkboxPlugin = require("workbox-webpack-plugin");
const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");
const package_json = require("./package.json");
const GIT_COMMIT = `${process.env.GITHUB_REF_NAME}.${process.env.GITHUB_SHA}`;
const GIT_BRANCH_MAIN = process.env.GITHUB_REF_NAME == "main";
const MODE = 'production';
const config = {
mode: MODE,
entry: [path.join(__dirname, "/src/app/app.js")],
// Render source-map file for final build
devtool: "source-map",
// output config
output: {
path: buildPath, // Path of output file
filename: "app.js", // Name of output file
},
plugins: [
new webpack.ProvidePlugin({
"React": "react",
}),
new CleanWebpackPlugin(),
// Define production build to allow React to strip out unnecessary checks
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(MODE),
SENTRY_DSN: JSON.stringify(process.env.SENTRY_DSN),
BUILD_DATE: JSON.stringify(new Date()),
GIT_COMMIT: JSON.stringify(GIT_COMMIT),
IS_DEVELOP: !GIT_BRANCH_MAIN
},
}),
// Allows error warnings but does not stop compiling.
new webpack.NoEmitOnErrorsPlugin(),
// Transfer Files
new CopyWebpackPlugin(
{
patterns: [
{ from: 'src/www/html' },
{ from: "src/www/images", to: "images" },
{ from: "src/www/images/icons-dev", to: !GIT_BRANCH_MAIN ? "images/icons" : "images/icons-dev"},
]
}
),
new WorkboxPlugin.GenerateSW({
clientsClaim: false, // Whether or not the service worker should start controlling any existing clients as soon as it activates.
skipWaiting: false,
maximumFileSizeToCacheInBytes: 10000000, // 10MB
runtimeCaching: [
{
urlPattern: /.*\.(?:png|jpg|jpeg|svg|gif)/,
handler: 'CacheFirst',
options: {
cacheName: 'images',
expiration: {
maxEntries: 10,
},
},
},
],
exclude: [
/.*\/images\/how-to-install\/.*$/,
],
disableDevLogs: false,
mode: MODE,
include: [
/\.html$/,
/\.js$/,
/\.jpg$/,
/\.svg$/,
/\.png$/,
/\.json$/,
/\.xml$/,
],
}),
sentryWebpackPlugin({
release: `${package_json.name}@${package_json.version}-${GIT_COMMIT}`,
include: "build",
ignoreFile: ".sentrycliignore",
ignore: [
"node_modules",
"webpack-dev-server.config.js",
"webpack-production.config.js",
],
}),
],
module: {
rules: [
{
// React-hot loader and
test: /\.js$/, // All .js files
loader: "babel-loader",
options: {
presets: ["@babel/env", "@babel/react"],
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime",
"@babel/transform-arrow-functions",
],
},
exclude: [nodeModulesPath],
},
{
test: /\.worker.js$/,
loader: "worker-loader",
options: {
inline: "fallback",
filename: "[name].[contenthash].worker.js",
},
},
{
test: /\.scss$/,
use: ["style-loader", "css-loader", "sass-loader"],
},
{
test: /\.(jpe?g|png|gif|svg|eot|woff|ttf|svg|woff2)$/,
use: [
{
loader: 'file-loader',
options: {
name : 'name=[name].[ext]'
}
}
]
},
],
},
};
module.exports = config;