snort/packages/app/webpack.config.js

200 lines
5.6 KiB
JavaScript
Raw Normal View History

2023-05-15 17:38:26 +00:00
// Generated using webpack-cli https://github.com/webpack/webpack-cli
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
2023-05-17 22:02:43 +00:00
const TerserPlugin = require("terser-webpack-plugin");
2023-05-15 17:38:26 +00:00
const ESLintPlugin = require("eslint-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
2023-05-17 22:36:34 +00:00
const CopyPlugin = require("copy-webpack-plugin");
2023-08-26 21:55:21 +00:00
const WorkboxPlugin = require("workbox-webpack-plugin");
const IntlTsTransformer = require("@formatjs/ts-transformer");
2023-09-27 10:36:37 +00:00
const { DefinePlugin } = require("webpack");
const appConfig = require("config");
2023-05-15 17:38:26 +00:00
const isProduction = process.env.NODE_ENV == "production";
const appTitle = appConfig.get("appTitle");
2023-11-02 17:39:42 +00:00
const gitVersion = require("child_process").execSync("git describe --always --tags").toString().trim();
const copyPatterns = [
{ from: "public/robots.txt" },
{ from: "public/nostrich_512.png" },
{ from: "public/nostrich_256.png" },
{ from: "_headers" },
];
if (appTitle === "iris") {
copyPatterns.push({ from: "public/iris/manifest_iris.json", to: "manifest.json" });
copyPatterns.push({ from: "public/iris/img", to: "img" });
copyPatterns.push({ from: "public/iris/.well-known", to: ".well-known" });
} else {
copyPatterns.push({ from: "public/manifest.json" });
2023-10-09 10:01:44 +00:00
copyPatterns.push({ from: "public/snort/.well-known", to: ".well-known" });
}
2023-05-15 17:38:26 +00:00
const config = {
2023-05-16 17:54:49 +00:00
entry: {
main: "./src/index.tsx",
2023-08-17 23:35:48 +00:00
pow: {
import: require.resolve("@snort/system/dist/pow-worker.js"),
filename: "pow.js",
},
2023-09-12 14:02:16 +00:00
bench: "./src/benchmarks.ts",
2023-05-16 17:54:49 +00:00
},
2023-05-15 17:38:26 +00:00
target: "browserslist",
2023-07-18 15:14:38 +00:00
mode: isProduction ? "production" : "development",
devtool: isProduction ? "source-map" : "cheap-module-source-map",
2023-05-15 17:38:26 +00:00
output: {
publicPath: "/",
path: path.resolve(__dirname, "build"),
2023-08-17 23:35:48 +00:00
filename: isProduction ? "[name].[chunkhash].js" : "[name].js",
2023-05-16 17:54:49 +00:00
clean: isProduction,
2023-05-15 17:38:26 +00:00
},
devServer: {
open: true,
2023-10-16 10:07:13 +00:00
https: true,
2023-05-15 17:38:26 +00:00
host: "localhost",
historyApiFallback: true,
},
plugins: [
2023-05-17 22:36:34 +00:00
new CopyPlugin({
patterns: copyPatterns,
2023-05-17 22:36:34 +00:00
}),
2023-05-15 17:38:26 +00:00
new HtmlWebpackPlugin({
template: "public/index.html",
2023-09-27 10:36:37 +00:00
favicon: appConfig.get("favicon"),
2023-09-11 15:46:50 +00:00
excludeChunks: ["pow", "bench"],
2023-09-26 05:02:42 +00:00
templateParameters: {
appTitle,
2023-10-04 13:53:12 +00:00
appleTouchIconUrl: appConfig.get("appleTouchIconUrl"),
2023-09-26 05:02:42 +00:00
},
2023-09-11 15:46:50 +00:00
}),
new HtmlWebpackPlugin({
filename: "bench.html",
template: "public/bench.html",
chunks: ["bench"],
2023-05-15 17:38:26 +00:00
}),
2023-07-18 15:14:38 +00:00
new ESLintPlugin({
extensions: ["js", "mjs", "jsx", "ts", "tsx"],
eslintPath: require.resolve("eslint"),
failOnError: true,
2023-07-18 15:14:38 +00:00
cache: true,
}),
2023-05-15 17:38:26 +00:00
new MiniCssExtractPlugin({
2023-05-16 17:54:49 +00:00
filename: isProduction ? "[name].[chunkhash].css" : "[name].css",
2023-05-15 17:38:26 +00:00
}),
2023-08-28 16:40:15 +00:00
isProduction
? new WorkboxPlugin.InjectManifest({
swSrc: "./src/service-worker.ts",
})
: false,
2023-09-26 05:02:42 +00:00
new DefinePlugin({
CONFIG: JSON.stringify(appConfig),
2023-10-31 15:40:12 +00:00
SINGLE_RELAY: JSON.stringify(process.env.SINGLE_RELAY),
2023-11-02 17:39:42 +00:00
GIT_VERSION: JSON.stringify(gitVersion),
2023-09-26 05:02:42 +00:00
}),
2023-05-15 17:38:26 +00:00
],
module: {
rules: [
2023-07-18 15:14:38 +00:00
{
enforce: "pre",
exclude: /@babel(?:\/|\\{1,2})runtime/,
test: /\.(js|mjs|jsx|ts|tsx|css)$/,
loader: require.resolve("source-map-loader"),
options: {
filterSourceMappingUrl: (url, resourcePath) => {
2023-08-26 21:55:21 +00:00
// disable warning for missing @scure-bip39 sourcemaps
if (/.*\/.yarn\/cache\/@scure-bip39.*/.test(resourcePath)) {
return false;
}
return true;
},
},
2023-07-18 15:14:38 +00:00
},
2023-05-15 17:38:26 +00:00
{
2023-05-19 14:15:13 +00:00
test: /\.tsx?$/i,
exclude: ["/node_modules/"],
2023-05-15 17:38:26 +00:00
use: [
{
2023-07-18 15:14:38 +00:00
loader: require.resolve("babel-loader"),
2023-05-15 17:38:26 +00:00
options: {
2023-07-18 15:14:38 +00:00
babelrc: false,
configFile: false,
2023-08-26 21:55:21 +00:00
presets: [["@babel/preset-env"], ["@babel/preset-react", { runtime: "automatic" }]],
2023-05-15 17:38:26 +00:00
},
2023-08-26 21:55:21 +00:00
},
{
loader: require.resolve("ts-loader"),
options: {
getCustomTransformers() {
return {
before: [
IntlTsTransformer.transform({
2023-08-26 21:55:21 +00:00
overrideIdFn: "[sha512:contenthash:base64:6]",
ast: true,
}),
2023-08-26 21:55:21 +00:00
],
};
},
2023-08-26 21:55:21 +00:00
},
},
2023-05-15 17:38:26 +00:00
],
},
{
test: /\.css$/i,
use: [
MiniCssExtractPlugin.loader,
require.resolve("css-loader"),
{
loader: require.resolve("postcss-loader"),
options: {
postcssOptions: {
plugins: [require("tailwindcss"), require("autoprefixer")],
},
},
},
],
2023-05-15 17:38:26 +00:00
},
{
2023-11-02 17:39:42 +00:00
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif|webp|wasm|md)$/i,
2023-05-15 17:38:26 +00:00
type: "asset",
},
],
},
optimization: {
2023-05-16 17:54:49 +00:00
chunkIds: "deterministic",
2023-05-17 22:02:43 +00:00
minimize: isProduction,
minimizer: [
new TerserPlugin({
terserOptions: {
parse: {
ecma: 8,
},
compress: {
ecma: 5,
warnings: false,
comparisons: false,
inline: 2,
},
mangle: {
safari10: true,
},
keep_classnames: isProduction,
2023-08-26 21:55:21 +00:00
keep_fnames: isProduction,
2023-05-17 22:02:43 +00:00
},
}),
new CssMinimizerPlugin(),
],
2023-05-15 17:38:26 +00:00
},
resolve: {
2023-07-13 21:44:26 +00:00
aliasFields: ["browser"],
extensions: ["...", ".tsx", ".ts", ".jsx", ".js"],
modules: ["...", __dirname, path.resolve(__dirname, "src")],
2023-08-26 21:55:21 +00:00
fallback: { crypto: false },
2023-09-12 14:02:16 +00:00
},
2023-05-15 17:38:26 +00:00
};
2023-07-18 15:14:38 +00:00
module.exports = () => config;