diff --git a/build-scripts/bundle.cjs b/build-scripts/bundle.cjs index cb9535c739..e5b41979ca 100644 --- a/build-scripts/bundle.cjs +++ b/build-scripts/bundle.cjs @@ -8,7 +8,7 @@ module.exports.sourceMapURL = () => { const ref = env.version().endsWith("dev") ? process.env.GITHUB_SHA || "dev" : env.version(); - return `https://raw.githubusercontent.com/home-assistant/frontend/${ref}`; + return `https://raw.githubusercontent.com/home-assistant/frontend/${ref}/`; }; // Files from NPM Packages that should not be imported diff --git a/build-scripts/webpack.cjs b/build-scripts/webpack.cjs index c5f8334149..13b7c75c6a 100644 --- a/build-scripts/webpack.cjs +++ b/build-scripts/webpack.cjs @@ -1,5 +1,6 @@ -const webpack = require("webpack"); +const { existsSync } = require("fs"); const path = require("path"); +const webpack = require("webpack"); const TerserPlugin = require("terser-webpack-plugin"); const { WebpackManifestPlugin } = require("webpack-manifest-plugin"); const log = require("fancy-log"); @@ -191,19 +192,23 @@ const createWebpackConfig = ({ // Since production source maps don't include sources, we need to point to them elsewhere // For dependencies, just provide the path (no source in browser) // Otherwise, point to the raw code on GitHub for browser to load - devtoolModuleFilenameTemplate: - !isTestBuild && isProdBuild - ? (info) => { - const sourcePath = info.resourcePath.replace(/^\.\//, ""); - if ( - sourcePath.startsWith("node_modules") || - sourcePath.startsWith("webpack") - ) { - return `no-source/${sourcePath}`; + ...Object.fromEntries( + ["", "Fallback"].map((v) => [ + `devtool${v}ModuleFilenameTemplate`, + !isTestBuild && isProdBuild + ? (info) => { + if ( + !path.isAbsolute(info.absoluteResourcePath) || + !existsSync(info.resourcePath) || + info.resourcePath.startsWith("./node_modules") + ) { + return new URL(info.resourcePath, "webpack://frontend/").href; + } + return new URL(info.resourcePath, bundle.sourceMapURL()).href; } - return `${bundle.sourceMapURL()}/${sourcePath}`; - } - : undefined, + : undefined, + ]) + ), }, experiments: { outputModule: true,