-
Notifications
You must be signed in to change notification settings - Fork 23
/
webpack.renderer.config.js
182 lines (165 loc) · 4.7 KB
/
webpack.renderer.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
170
171
172
173
174
175
176
177
178
179
180
181
182
"use strict";
import * as path from "path";
import webpack from "webpack";
import "dotenv/config";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import { sentryWebpackPlugin } from "@sentry/webpack-plugin";
import ESLintPlugin from "eslint-webpack-plugin";
import { readFile } from 'fs/promises';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const packageJSON = JSON.parse(
await readFile(
new URL('./package.json', import.meta.url)
)
);
const productName = packageJSON.productName;
const outputDir = path.join(__dirname, "output");
const COMMIT_SHA = process.env.SENTRY_RELEASE || process.env.GITHUB_SHA;
var htmlPageOptions = function(id, title) {
return {
filename: `${id}.html`,
template: path.resolve(__dirname, "src/index.ejs"),
id: id,
title: `${productName}: ${title}`,
minify: {
collapseWhitespace: false,
removeAttributeQuotes: false,
removeComments: false
}
};
};
/**
* List of node_modules to include in webpack bundle
*
* Required for specific packages like Vue UI libraries
* that provide pure *.vue files that need compiling
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/webpack-configurations.html#white-listing-externals
*/
// let whiteListedModules = [];
// let externals = [
// ...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d))
// ];
// console.log("EXTERNALS", externals);
let rendererConfig = {
devtool: "inline-source-map",
entry: {
renderer: path.join(__dirname, "src", "renderer", "main.js")
},
// externals: externals,
module: {
rules: [
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"sass-loader",
]
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"]
}
}
},
{
test: /\.svelte$/,
use: {
loader: "svelte-loader",
options: {
emitCss: true,
}
},
},
{
// required to prevent errors from Svelte on Webpack 5+, omit on Webpack 4
test: /node_modules\/svelte\/.*\.mjs$/,
resolve: {
fullySpecified: false
}
},
]
},
node: {
__dirname: false,
__filename: false
},
plugins: [
new ESLintPlugin({
fix: false,
configType: 'flat',
extensions: ["js"]
}),
new HtmlWebpackPlugin(htmlPageOptions("prefs", "Preferences")),
new HtmlWebpackPlugin(htmlPageOptions("settings", "Settings")),
new HtmlWebpackPlugin(htmlPageOptions("editor", "Editor")),
new HtmlWebpackPlugin(htmlPageOptions("new", "Create Screensaver!")),
new HtmlWebpackPlugin(htmlPageOptions("about", "About!")),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css"
}),
],
optimization: {
emitOnErrors: false,
nodeEnv: (process.env.NODE_ENV === "production" ? "production" : "development")
},
output: {
filename: "[name].js",
library: "[name]",
libraryTarget: "var",
path: outputDir,
publicPath: ""
},
mode: (process.env.NODE_ENV === "production" ? "production" : "development"),
resolve: {
alias: {
// handy alias for the root path of render files
"@": path.join(__dirname, "src", "renderer"),
"~": path.join(__dirname, "src")
},
extensions: [".js", ".json", ".css", ".svelte"],
conditionNames: ["svelte", "browser", "import"]
},
target: "web"
};
/**
* Adjust rendererConfig for production settings
*/
if (process.env.NODE_ENV === "production") {
rendererConfig.devtool = "source-map";
if ( process.env.SENTRY_DSN ) {
rendererConfig.plugins.push(
new webpack.EnvironmentPlugin(["SENTRY_DSN"])
);
}
rendererConfig.plugins.push(
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("production"),
"process.env.BEFORE_DAWN_RELEASE_NAME": JSON.stringify(COMMIT_SHA),
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
);
if ( process.env.SENTRY_AUTH_TOKEN && !process.env.DISABLE_SENTRY ) {
rendererConfig.plugins.push(
sentryWebpackPlugin({
include: "src",
ignoreFile: ".sentrycliignore",
ignore: ["node_modules", "webpack.config.js", "webpack.main.config.js", "webpack.renderer.config.js"],
org: "colin-mitchell",
project: "before-dawn",
authToken: process.env.SENTRY_AUTH_TOKEN,
release: COMMIT_SHA,
})
);
}
}
export default rendererConfig;