browsertrix/frontend/webpack.config.js
Emma Segal-Grossman 73e20269ef
Org settings layout fix + misc styling & consistency improvements (#1427)
## General changes

- Added `postcss-lit`, which allows us to use tailwind in lit elements
with shadow DOMs
- Added `// postcss-lit-disable-next-line` comments to most `` css`...`
`` tagged templates so as not to change existing CSS in components
- Added `TailwindElement`, which uses a single shared `CSSStyleSheet`
across all instances to be able to access Tailwind without requiring a
full copy of (compiled) Tailwind for every instance of a component that
extends it
- Added a new `<btrix-copy-field>` element, replacing the existing copy
elements

## Org settings page

- Stopped content from overflowing at medium widths
- Made spacing consistent at both smaller and wider widths
- Used readonly/monospace styling for copyable org id field
- Updated tab shadows to be slightly blue, consistent with the tab
background (also did this in other places tabs show up)

Before | After
-|-
![dev browsertrix
cloud_orgs_default-org_settings](https://github.com/webrecorder/browsertrix-cloud/assets/5727389/9bcacdcc-259b-4a01-bac5-8913518776f0)
|
![localhost_9870_orgs_default-org_workflows_crawls](https://github.com/webrecorder/browsertrix-cloud/assets/5727389/53936d4d-e5cd-4f37-ad06-b3b5041381df)
![dev browsertrix cloud_orgs_default-org_settings
(3)](https://github.com/webrecorder/browsertrix-cloud/assets/5727389/602dd8d6-3012-4a0e-a638-a5192c9601ec)
| ![localhost_9870_orgs_default-org_workflows_crawls
(3)](https://github.com/webrecorder/browsertrix-cloud/assets/5727389/74c93312-ad26-48d8-a87e-3da9a851693b)

## Misc fixes

- Used consistent single-line readonly/monospace styling for copyable
url field

Before | After
-|-
![dev browsertrix cloud_orgs_default-org_settings
(1)](https://github.com/webrecorder/browsertrix-cloud/assets/5727389/e361feeb-3ea0-4f56-9e38-12ef6a644d58)
| ![localhost_9870_orgs_default-org_workflows_crawls
(1)](https://github.com/webrecorder/browsertrix-cloud/assets/5727389/0145b1ad-8f45-4486-893e-8f638ac9add6)

- Removed inconsistent angled bottom borders from crawl workflow list
header

Before | After
-|-
![dev browsertrix cloud_orgs_default-org_settings
(2)](https://github.com/webrecorder/browsertrix-cloud/assets/5727389/4aa20359-3ecf-4441-83c0-ed36a951ed3b)
| ![localhost_9870_orgs_default-org_workflows_crawls
(2)](https://github.com/webrecorder/browsertrix-cloud/assets/5727389/8c771464-3a70-47e7-8475-fa82d4d030a9)

- Changes _all_ list page primary action buttons to use
`variant="primary"`

<img width="190" alt="Screenshot 2023-12-08 at 11 23 49 AM"
src="https://github.com/webrecorder/browsertrix-cloud/assets/5672810/2b007f5e-e675-40b2-86a7-f0bf8ef83b81">
<img width="240" alt="Screenshot 2023-12-08 at 11 23 43 AM"
src="https://github.com/webrecorder/browsertrix-cloud/assets/5672810/621b340e-2051-4ab0-8f42-8f0a51d8d3a5">

---------

Co-authored-by: Henry Wilkinson <henry@wilkinson.graphics>
Co-authored-by: sua yoo <sua@webrecorder.org>
Co-authored-by: sua yoo <sua@suayoo.com>
2023-12-13 17:29:35 -05:00

218 lines
5.8 KiB
JavaScript

// cSpell:ignore glitchtip
// webpack.config.js
const path = require("path");
const webpack = require("webpack");
const ESLintPlugin = require("eslint-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const childProcess = require("child_process");
const packageJSON = require("./package.json");
const fs = require("fs");
const isDevServer = process.env.WEBPACK_SERVE;
const dotEnvPath = path.resolve(
process.cwd(),
`.env${isDevServer ? `.local` : ""}`
);
require("dotenv").config({
path: dotEnvPath,
});
// for testing: for prod, the Dockerfile should have the official prod version used
const _RWP_BASE_URL = process.env.RWP_BASE_URL || "https://replayweb.page/";
const WEBSOCKET_HOST =
isDevServer && process.env.API_BASE_URL
? new URL(process.env.API_BASE_URL).host
: process.env.WEBSOCKET_HOST || "";
// Get git info for release version info
const execCommand = (cmd, defValue) => {
try {
return childProcess.execSync(cmd).toString().trim();
} catch (e) {
return defValue;
}
};
// Local dev only
// Git branch and commit hash is used to add build info to error reporter when running locally
const gitBranch =
process.env.GIT_BRANCH_NAME ||
execCommand("git rev-parse --abbrev-ref HEAD", "unknown");
const commitHash =
process.env.GIT_COMMIT_HASH ||
execCommand("git rev-parse --short HEAD", "unknown");
const shoelaceAssetsSrcPath = path.resolve(
__dirname,
"node_modules/@shoelace-style/shoelace/dist/assets"
);
const shoelaceAssetsPublicPath = "shoelace/assets";
const version = (() => {
if (process.env.VERSION) {
return process.env.VERSION;
}
try {
return fs.readFileSync("../version.txt", { encoding: "utf-8" }).trim();
} catch (e) {}
return packageJSON.version;
})();
/** @type {import('webpack').Configuration} */
const main = {
entry: "./src/index.ts",
output: {
path: path.resolve(__dirname, "dist"),
filename: `js/[name]${isDevServer ? "" : ".[contenthash]"}.js`,
publicPath: "/",
hashFunction: "xxhash64",
},
module: {
rules: [
{
test: /\.ts$/,
include: path.resolve(__dirname, "src"),
use: [
{
loader: "postcss-loader",
options: {
/** @type {import('postcss-load-config').Config} */
postcssOptions: {
syntax: "postcss-lit",
plugins: [["tailwindcss"], ["autoprefixer"]],
},
},
},
{
loader: "ts-loader",
options: {
onlyCompileBundledFiles: true,
transpileOnly: true,
},
},
],
exclude: /node_modules/,
},
{
// Non-theme styles and assets like fonts and Shoelace
test: /\.css$/,
include: [
path.resolve(__dirname, "src"),
path.resolve(__dirname, "node_modules/@shoelace-style/shoelace"),
],
exclude: [path.resolve(__dirname, "src/theme.css")],
use: [
"style-loader",
{ loader: "css-loader", options: { importLoaders: 1 } },
"postcss-loader",
],
},
{
// Theme CSS loaded as raw string and used as a CSSStyleSheet
test: /theme\.css$/,
type: "asset/source",
include: [path.resolve(__dirname, "src")],
use: ["postcss-loader"],
},
{
test: /\.html$/,
include: path.resolve(__dirname, "src"),
loader: "html-loader",
},
{
test: /\.(woff(2)?|ttf|svg|webp)(\?v=\d+\.\d+\.\d+)?$/,
include: path.resolve(__dirname, "src"),
type: "asset/resource",
},
],
},
resolve: {
extensions: [".ts", ".js"],
plugins: [new TsconfigPathsPlugin()],
},
plugins: [
new webpack.DefinePlugin({
"process.env.WEBSOCKET_HOST": JSON.stringify(WEBSOCKET_HOST),
}),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 12,
}),
new ForkTsCheckerWebpackPlugin({
typescript: { configOverwrite: { exclude: ["**/*.test.ts"] } },
}),
new HtmlWebpackPlugin({
template: "src/index.ejs",
templateParameters: {
glitchtip_dsn: process.env.GLITCHTIP_DSN || "",
environment: isDevServer ? "development" : "production",
version,
gitBranch,
commitHash,
},
// TODO this breaks shoelace forms, but seems HMR is broken anyway?
// // Need to block during local development for HMR:
// inject: isDevServer ? "head" : true,
// scriptLoading: isDevServer ? "blocking" : "defer",
inject: true,
scriptLoading: "defer",
}),
// Lint js files
new ESLintPlugin({
// lint only changed files:
lintDirtyModulesOnly: true,
// prevent warnings from stopping dev build
emitWarning: false,
// enable to auto-fix source files:
// fix: true
}),
new CopyPlugin({
patterns: [
// Copy Shoelace assets to dist/shoelace
{
from: shoelaceAssetsSrcPath,
to: path.resolve(__dirname, "dist", shoelaceAssetsPublicPath),
},
// Copy custom icon library
{
from: path.resolve(__dirname, "src/assets/icons"),
to: path.resolve(__dirname, "dist", "assets/icons"),
},
],
}),
...(process.env.BUNDLE_ANALYZER
? [new (require("webpack-bundle-analyzer").BundleAnalyzerPlugin)()]
: []),
],
};
const vnc = {
entry: "./node_modules/@novnc/novnc/core/rfb.js",
experiments: { outputModule: true },
output: {
filename: "js/novnc.js",
library: {
type: "module",
},
hashFunction: "xxhash64",
},
};
module.exports = [main, vnc];