2018-06-05 05:10:41 +02:00
|
|
|
const path = require("path");
|
2018-06-05 06:02:43 +02:00
|
|
|
const fs = require("fs");
|
2018-06-05 05:10:41 +02:00
|
|
|
const webpack = require("webpack");
|
2021-04-22 21:29:29 +02:00
|
|
|
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
|
2018-06-05 05:10:41 +02:00
|
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
2021-10-05 12:03:24 +02:00
|
|
|
const HtmlWebpackInjector = require("html-webpack-injector");
|
2018-06-05 05:10:41 +02:00
|
|
|
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
2020-05-08 17:42:28 +02:00
|
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
2019-04-21 02:54:50 +02:00
|
|
|
const TerserPlugin = require("terser-webpack-plugin");
|
2021-12-09 22:12:53 +01:00
|
|
|
const { AngularWebpackPlugin } = require("@ngtools/webpack");
|
2018-06-11 15:31:11 +02:00
|
|
|
const pjson = require("./package.json");
|
2021-05-27 18:46:26 +02:00
|
|
|
const config = require("./config.js");
|
2018-06-05 05:10:41 +02:00
|
|
|
|
2021-05-27 18:46:26 +02:00
|
|
|
const ENV = process.env.ENV == null ? "development" : process.env.ENV;
|
|
|
|
const NODE_ENV = process.env.NODE_ENV == null ? "development" : process.env.NODE_ENV;
|
2021-04-21 20:29:33 +02:00
|
|
|
|
2021-08-25 20:15:31 +02:00
|
|
|
const envConfig = config.load(ENV);
|
2021-05-27 18:46:26 +02:00
|
|
|
config.log(envConfig);
|
2018-06-05 05:10:41 +02:00
|
|
|
|
|
|
|
const moduleRules = [
|
|
|
|
{
|
|
|
|
test: /\.ts$/,
|
|
|
|
enforce: "pre",
|
|
|
|
loader: "tslint-loader",
|
2021-12-17 15:57:11 +01:00
|
|
|
},
|
|
|
|
{
|
2018-06-05 05:10:41 +02:00
|
|
|
test: /\.(html)$/,
|
|
|
|
loader: "html-loader",
|
2021-12-17 15:57:11 +01:00
|
|
|
},
|
|
|
|
{
|
2018-07-18 16:32:44 +02:00
|
|
|
test: /.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
|
2021-09-30 00:06:20 +02:00
|
|
|
exclude: /loading(|-white).svg/,
|
2021-12-09 22:12:53 +01:00
|
|
|
generator: {
|
2022-01-14 13:35:44 +01:00
|
|
|
filename: "fonts/[name][ext]",
|
2018-06-05 05:10:41 +02:00
|
|
|
},
|
2021-12-09 22:12:53 +01:00
|
|
|
type: "asset/resource",
|
2018-07-18 16:32:44 +02:00
|
|
|
},
|
2018-06-05 15:01:40 +02:00
|
|
|
{
|
2022-01-10 12:37:21 +01:00
|
|
|
test: /\.(jpe?g|png|gif|svg|webp|avif)$/i,
|
2018-06-11 18:58:56 +02:00
|
|
|
exclude: /.*(fontawesome-webfont)\.svg/,
|
2021-12-09 22:12:53 +01:00
|
|
|
generator: {
|
2022-01-14 13:35:44 +01:00
|
|
|
filename: "images/[name][ext]",
|
2021-04-22 21:29:29 +02:00
|
|
|
},
|
2021-12-09 22:12:53 +01:00
|
|
|
type: "asset/resource",
|
2021-12-17 15:57:11 +01:00
|
|
|
},
|
|
|
|
{
|
2018-06-05 05:10:41 +02:00
|
|
|
test: /\.scss$/,
|
2021-12-17 15:57:11 +01:00
|
|
|
use: [
|
|
|
|
{
|
2020-05-08 17:42:28 +02:00
|
|
|
loader: MiniCssExtractPlugin.loader,
|
2021-12-17 15:57:11 +01:00
|
|
|
},
|
2020-05-08 17:42:28 +02:00
|
|
|
"css-loader",
|
2020-05-08 17:54:49 +02:00
|
|
|
"sass-loader",
|
2021-12-17 15:57:11 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2021-04-22 21:29:29 +02:00
|
|
|
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
|
|
|
|
loader: "@ngtools/webpack",
|
2021-12-17 15:57:11 +01:00
|
|
|
},
|
2018-06-05 05:10:41 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
const plugins = [
|
2021-04-22 21:29:29 +02:00
|
|
|
new CleanWebpackPlugin(),
|
2018-06-05 05:10:41 +02:00
|
|
|
// ref: https://github.com/angular/angular/issues/20357
|
2018-09-11 23:30:44 +02:00
|
|
|
new webpack.ContextReplacementPlugin(
|
|
|
|
/\@angular(\\|\/)core(\\|\/)fesm5/,
|
2018-06-05 05:10:41 +02:00
|
|
|
path.resolve(__dirname, "./src")
|
|
|
|
),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: "./src/index.html",
|
|
|
|
filename: "index.html",
|
2021-10-05 12:03:24 +02:00
|
|
|
chunks: ["theme_head", "app/polyfills", "app/vendor", "app/main"],
|
2018-06-05 15:01:40 +02:00
|
|
|
}),
|
2021-10-05 12:03:24 +02:00
|
|
|
new HtmlWebpackInjector(),
|
2018-06-05 15:01:40 +02:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: "./src/connectors/duo.html",
|
|
|
|
filename: "duo-connector.html",
|
|
|
|
chunks: ["connectors/duo"],
|
|
|
|
}),
|
2021-03-16 17:44:31 +01:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: "./src/connectors/webauthn.html",
|
|
|
|
filename: "webauthn-connector.html",
|
|
|
|
chunks: ["connectors/webauthn"],
|
|
|
|
}),
|
2021-08-26 17:39:52 +02:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: "./src/connectors/webauthn-mobile.html",
|
|
|
|
filename: "webauthn-mobile-connector.html",
|
|
|
|
chunks: ["connectors/webauthn"],
|
|
|
|
}),
|
2021-03-16 17:44:31 +01:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: "./src/connectors/webauthn-fallback.html",
|
|
|
|
filename: "webauthn-fallback-connector.html",
|
|
|
|
chunks: ["connectors/webauthn-fallback"],
|
|
|
|
}),
|
2020-07-16 15:18:25 +02:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: "./src/connectors/sso.html",
|
|
|
|
filename: "sso-connector.html",
|
|
|
|
chunks: ["connectors/sso"],
|
|
|
|
}),
|
2021-06-22 21:35:33 +02:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: "./src/connectors/captcha.html",
|
|
|
|
filename: "captcha-connector.html",
|
|
|
|
chunks: ["connectors/captcha"],
|
|
|
|
}),
|
2021-07-23 21:30:04 +02:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: "./src/connectors/captcha-mobile.html",
|
|
|
|
filename: "captcha-mobile-connector.html",
|
|
|
|
chunks: ["connectors/captcha"],
|
|
|
|
}),
|
2021-04-22 21:29:29 +02:00
|
|
|
new CopyWebpackPlugin({
|
|
|
|
patterns: [
|
|
|
|
{ from: "./src/.nojekyll" },
|
|
|
|
{ from: "./src/manifest.json" },
|
|
|
|
{ from: "./src/favicon.ico" },
|
|
|
|
{ from: "./src/browserconfig.xml" },
|
|
|
|
{ from: "./src/app-id.json" },
|
|
|
|
{ from: "./src/404.html" },
|
|
|
|
{ from: "./src/404", to: "404" },
|
|
|
|
{ from: "./src/images", to: "images" },
|
|
|
|
{ from: "./src/locales", to: "locales" },
|
|
|
|
{ from: "./node_modules/qrious/dist/qrious.min.js", to: "scripts" },
|
|
|
|
{ from: "./node_modules/braintree-web-drop-in/dist/browser/dropin.js", to: "scripts" },
|
2021-09-24 18:24:58 +02:00
|
|
|
{
|
|
|
|
from: "./src/version.json",
|
|
|
|
transform(content, path) {
|
|
|
|
return content.toString().replace("process.env.APPLICATION_VERSION", pjson.version);
|
|
|
|
},
|
|
|
|
},
|
2021-04-22 21:29:29 +02:00
|
|
|
],
|
|
|
|
}),
|
2020-05-08 17:42:28 +02:00
|
|
|
new MiniCssExtractPlugin({
|
2021-12-09 22:12:53 +01:00
|
|
|
filename: "[name].[contenthash].css",
|
|
|
|
chunkFilename: "[id].[contenthash].css",
|
2020-05-08 17:42:28 +02:00
|
|
|
}),
|
2021-07-26 15:51:25 +02:00
|
|
|
new webpack.EnvironmentPlugin({
|
|
|
|
ENV: ENV,
|
|
|
|
NODE_ENV: NODE_ENV === "production" ? "production" : "development",
|
|
|
|
APPLICATION_VERSION: pjson.version,
|
|
|
|
CACHE_TAG: Math.random().toString(36).substring(7),
|
2021-08-25 20:15:31 +02:00
|
|
|
URLS: envConfig["urls"] ?? {},
|
2021-09-09 23:18:46 +02:00
|
|
|
STRIPE_KEY: envConfig["stripeKey"] ?? "",
|
|
|
|
BRAINTREE_KEY: envConfig["braintreeKey"] ?? "",
|
|
|
|
PAYPAL_CONFIG: envConfig["paypal"] ?? {},
|
2018-06-05 05:10:41 +02:00
|
|
|
}),
|
2021-12-09 22:12:53 +01:00
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
process: "process/browser",
|
|
|
|
}),
|
|
|
|
new AngularWebpackPlugin({
|
2018-06-05 05:10:41 +02:00
|
|
|
tsConfigPath: "tsconfig.json",
|
|
|
|
entryModule: "src/app/app.module#AppModule",
|
|
|
|
sourceMap: true,
|
2021-04-22 21:29:29 +02:00
|
|
|
}),
|
|
|
|
];
|
2018-06-05 05:10:41 +02:00
|
|
|
|
2018-09-18 17:59:03 +02:00
|
|
|
// ref: https://webpack.js.org/configuration/dev-server/#devserver
|
2018-06-05 17:14:53 +02:00
|
|
|
let certSuffix = fs.existsSync("dev-server.local.pem") ? ".local" : ".shared";
|
2021-10-22 14:50:08 +02:00
|
|
|
const devServer =
|
|
|
|
NODE_ENV !== "development"
|
|
|
|
? {}
|
|
|
|
: {
|
2021-12-09 22:12:53 +01:00
|
|
|
server: {
|
|
|
|
type: "https",
|
|
|
|
options: {
|
|
|
|
key: fs.readFileSync("dev-server" + certSuffix + ".pem"),
|
|
|
|
cert: fs.readFileSync("dev-server" + certSuffix + ".pem"),
|
2021-12-17 15:57:11 +01:00
|
|
|
},
|
2021-12-09 22:12:53 +01:00
|
|
|
},
|
2018-07-10 16:47:31 +02:00
|
|
|
// host: '192.168.1.9',
|
2021-04-05 22:38:21 +02:00
|
|
|
proxy: {
|
|
|
|
"/api": {
|
2021-10-22 14:50:08 +02:00
|
|
|
target: envConfig.dev?.proxyApi,
|
2021-04-09 09:57:25 +02:00
|
|
|
pathRewrite: { "^/api": "" },
|
|
|
|
secure: false,
|
|
|
|
changeOrigin: true,
|
2021-04-05 22:38:21 +02:00
|
|
|
},
|
|
|
|
"/identity": {
|
2021-10-22 14:50:08 +02:00
|
|
|
target: envConfig.dev?.proxyIdentity,
|
2021-04-09 09:57:25 +02:00
|
|
|
pathRewrite: { "^/identity": "" },
|
|
|
|
secure: false,
|
|
|
|
changeOrigin: true,
|
2021-04-05 22:38:21 +02:00
|
|
|
},
|
|
|
|
"/events": {
|
2021-10-22 14:50:08 +02:00
|
|
|
target: envConfig.dev?.proxyEvents,
|
2021-04-09 09:57:25 +02:00
|
|
|
pathRewrite: { "^/events": "" },
|
2021-04-05 22:38:21 +02:00
|
|
|
secure: false,
|
|
|
|
changeOrigin: true,
|
|
|
|
},
|
2021-04-09 09:57:25 +02:00
|
|
|
"/notifications": {
|
2021-10-22 14:50:08 +02:00
|
|
|
target: envConfig.dev?.proxyNotifications,
|
2021-04-09 09:57:25 +02:00
|
|
|
pathRewrite: { "^/notifications": "" },
|
2021-04-05 22:38:21 +02:00
|
|
|
secure: false,
|
|
|
|
changeOrigin: true,
|
2021-12-17 15:57:11 +01:00
|
|
|
},
|
2021-04-05 22:38:21 +02:00
|
|
|
},
|
2021-04-09 09:57:25 +02:00
|
|
|
hot: false,
|
2021-12-09 22:12:53 +01:00
|
|
|
allowedHosts: envConfig.dev?.allowedHosts ?? "auto",
|
|
|
|
client: {
|
|
|
|
overlay: {
|
|
|
|
errors: true,
|
|
|
|
warnings: false,
|
2021-12-17 15:57:11 +01:00
|
|
|
},
|
2021-12-09 22:12:53 +01:00
|
|
|
},
|
2021-04-09 09:57:25 +02:00
|
|
|
};
|
|
|
|
|
2021-04-21 20:29:33 +02:00
|
|
|
const webpackConfig = {
|
|
|
|
mode: NODE_ENV,
|
2018-06-05 17:52:09 +02:00
|
|
|
devtool: "source-map",
|
2018-09-18 17:59:03 +02:00
|
|
|
devServer: devServer,
|
2018-06-05 05:10:41 +02:00
|
|
|
entry: {
|
2018-06-08 05:38:17 +02:00
|
|
|
"app/polyfills": "./src/app/polyfills.ts",
|
2018-06-05 15:01:40 +02:00
|
|
|
"app/main": "./src/app/main.ts",
|
2021-03-16 17:44:31 +01:00
|
|
|
"connectors/webauthn": "./src/connectors/webauthn.ts",
|
|
|
|
"connectors/webauthn-fallback": "./src/connectors/webauthn-fallback.ts",
|
2018-06-08 16:15:45 +02:00
|
|
|
"connectors/duo": "./src/connectors/duo.ts",
|
2020-07-16 15:18:25 +02:00
|
|
|
"connectors/sso": "./src/connectors/sso.ts",
|
2021-06-22 21:35:33 +02:00
|
|
|
"connectors/captcha": "./src/connectors/captcha.ts",
|
2021-10-05 12:03:24 +02:00
|
|
|
theme_head: "./src/theme.js",
|
2018-06-05 05:10:41 +02:00
|
|
|
},
|
2018-07-21 04:46:03 +02:00
|
|
|
optimization: {
|
|
|
|
splitChunks: {
|
|
|
|
cacheGroups: {
|
|
|
|
commons: {
|
|
|
|
test: /[\\/]node_modules[\\/]/,
|
|
|
|
name: "app/vendor",
|
|
|
|
chunks: (chunk) => {
|
|
|
|
return chunk.name === "app/main";
|
|
|
|
},
|
|
|
|
},
|
2019-04-21 02:54:50 +02:00
|
|
|
},
|
2018-07-21 04:46:03 +02:00
|
|
|
},
|
2018-06-05 05:10:41 +02:00
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin({
|
|
|
|
terserOptions: {
|
|
|
|
safari10: true,
|
2021-12-09 22:12:53 +01:00
|
|
|
},
|
2021-12-17 15:57:11 +01:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
resolve: {
|
2018-06-05 05:10:41 +02:00
|
|
|
extensions: [".ts", ".js"],
|
|
|
|
symlinks: false,
|
|
|
|
modules: [path.resolve("node_modules")],
|
2021-12-09 22:12:53 +01:00
|
|
|
fallback: {
|
|
|
|
buffer: false,
|
|
|
|
util: require.resolve("util/"),
|
|
|
|
assert: false,
|
2018-06-05 05:10:41 +02:00
|
|
|
},
|
2021-12-17 15:57:11 +01:00
|
|
|
},
|
2018-06-05 05:10:41 +02:00
|
|
|
output: {
|
2021-12-09 22:12:53 +01:00
|
|
|
filename: "[name].[contenthash].js",
|
2018-06-05 05:10:41 +02:00
|
|
|
path: path.resolve(__dirname, "build"),
|
|
|
|
},
|
|
|
|
module: { rules: moduleRules },
|
|
|
|
plugins: plugins,
|
|
|
|
};
|
|
|
|
|
2021-04-21 20:29:33 +02:00
|
|
|
module.exports = webpackConfig;
|