webpack_public_path: Replace with webpack 5 publicPath: "auto" setting.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-15 21:58:50 -07:00 committed by Tim Abbott
parent b605042312
commit 94934f49f9
8 changed files with 7 additions and 20 deletions

View File

@ -273,7 +273,6 @@ EXEMPT_FILES = make_set(
"web/src/user_topics.ts", "web/src/user_topics.ts",
"web/src/user_topics_ui.js", "web/src/user_topics_ui.js",
"web/src/views_util.js", "web/src/views_util.js",
"web/src/webpack_public_path.js",
"web/src/zcommand.js", "web/src/zcommand.js",
"web/src/zform.js", "web/src/zform.js",
"web/src/zulip.js", "web/src/zulip.js",

View File

@ -1,5 +1,4 @@
import "../sentry"; import "../sentry";
import "../webpack_public_path";
import "../../debug-require"; import "../../debug-require";
import "../alert_popup"; import "../alert_popup";
import "../csrf"; import "../csrf";

View File

@ -90,7 +90,6 @@ export const page_params: {
show_webathena: boolean; show_webathena: boolean;
translation_data: Record<string, string>; translation_data: Record<string, string>;
user_id: number | undefined; user_id: number | undefined;
webpack_public_path: string;
zulip_merge_base: string; zulip_merge_base: string;
zulip_plan_is_not_limited: boolean; zulip_plan_is_not_limited: boolean;
zulip_version: string; zulip_version: string;

View File

@ -31,7 +31,12 @@ export function shouldCreateSpanForRequest(url: string): boolean {
} }
if (page_params.server_sentry_dsn) { if (page_params.server_sentry_dsn) {
const url_matches = [/^\//, new RegExp("^" + _.escapeRegExp(page_params.webpack_public_path))]; const url_matches = [/^\//];
if (document.currentScript instanceof HTMLScriptElement) {
url_matches.push(
new RegExp("^" + _.escapeRegExp(new URL(".", document.currentScript.src).href)),
);
}
if (page_params.realm_uri !== undefined) { if (page_params.realm_uri !== undefined) {
url_matches.push(new RegExp("^" + _.escapeRegExp(page_params.realm_uri) + "/")); url_matches.push(new RegExp("^" + _.escapeRegExp(page_params.realm_uri) + "/"));
} }

View File

@ -1,11 +0,0 @@
/* eslint-env commonjs */
// eslint-disable-next-line no-unused-vars
/* global __webpack_public_path__:writable */
"use strict";
const {page_params} = require("./page_params");
// Webpack exposes this global for dynamic configuration of publicPath.
// https://webpack.js.org/guides/public-path/#on-the-fly
__webpack_public_path__ = page_params.webpack_public_path;

View File

@ -163,7 +163,7 @@ export default (
}, },
output: { output: {
path: path.resolve(__dirname, "../static/webpack-bundles"), path: path.resolve(__dirname, "../static/webpack-bundles"),
publicPath: "", publicPath: "auto",
filename: production ? "[name].[contenthash].js" : "[name].js", filename: production ? "[name].[contenthash].js" : "[name].js",
assetModuleFilename: production assetModuleFilename: production
? "files/[name].[hash][ext][query]" ? "files/[name].[hash][ext][query]"

View File

@ -2,7 +2,6 @@ from typing import Any, Dict, Mapping, Optional
from urllib.parse import urljoin from urllib.parse import urljoin
from django.conf import settings from django.conf import settings
from django.contrib.staticfiles.storage import staticfiles_storage
from django.http import HttpRequest from django.http import HttpRequest
from django.utils.html import escape from django.utils.html import escape
from django.utils.safestring import SafeString from django.utils.safestring import SafeString
@ -32,7 +31,6 @@ from zproject.config import get_config
DEFAULT_PAGE_PARAMS: Mapping[str, Any] = { DEFAULT_PAGE_PARAMS: Mapping[str, Any] = {
"development_environment": settings.DEVELOPMENT, "development_environment": settings.DEVELOPMENT,
"webpack_public_path": staticfiles_storage.url(settings.WEBPACK_BUNDLES),
} }

View File

@ -226,7 +226,6 @@ class HomeTest(ZulipTestCase):
"user_status", "user_status",
"user_topics", "user_topics",
"warn_no_email", "warn_no_email",
"webpack_public_path",
"zulip_feature_level", "zulip_feature_level",
"zulip_merge_base", "zulip_merge_base",
"zulip_plan_is_not_limited", "zulip_plan_is_not_limited",
@ -368,7 +367,6 @@ class HomeTest(ZulipTestCase):
"two_fa_enabled", "two_fa_enabled",
"two_fa_enabled_user", "two_fa_enabled_user",
"warn_no_email", "warn_no_email",
"webpack_public_path",
] ]
self.assertEqual(actual_keys, expected_keys) self.assertEqual(actual_keys, expected_keys)