diff --git a/build-scripts/bundle.js b/build-scripts/bundle.js index 2c93bd7835..50e24db416 100644 --- a/build-scripts/bundle.js +++ b/build-scripts/bundle.js @@ -178,7 +178,6 @@ module.exports.config = { publicPath: publicPath(latestBuild, paths.hassio_publicPath), isProdBuild, latestBuild, - dontHash: new Set(["entrypoint"]), }; }, diff --git a/build-scripts/gulp/entry-html.js b/build-scripts/gulp/entry-html.js index c1be430039..f79950e156 100644 --- a/build-scripts/gulp/entry-html.js +++ b/build-scripts/gulp/entry-html.js @@ -90,8 +90,6 @@ gulp.task("gen-pages-prod", (done) => { }); gulp.task("gen-index-app-dev", (done) => { - // In dev mode we don't mangle names, so we hardcode urls. That way we can - // run webpack as last in watch mode, which blocks output. const content = renderTemplate("index", { latestAppJS: "/frontend_latest/app.js", latestCoreJS: "/frontend_latest/core.js", @@ -201,8 +199,6 @@ gulp.task("gen-index-cast-prod", (done) => { }); gulp.task("gen-index-demo-dev", (done) => { - // In dev mode we don't mangle names, so we hardcode urls. That way we can - // run webpack as last in watch mode, which blocks output. const content = renderDemoTemplate("index", { latestDemoJS: "/frontend_latest/main.js", @@ -240,8 +236,6 @@ gulp.task("gen-index-demo-prod", (done) => { }); gulp.task("gen-index-gallery-dev", (done) => { - // In dev mode we don't mangle names, so we hardcode urls. That way we can - // run webpack as last in watch mode, which blocks output. const content = renderGalleryTemplate("index", { latestGalleryJS: "./frontend_latest/entrypoint.js", }); @@ -269,3 +263,39 @@ gulp.task("gen-index-gallery-prod", (done) => { ); done(); }); + +gulp.task("gen-index-hassio-dev", async () => { + writeHassioEntrypoint("entrypoint.js", "entrypoints.js"); +}); + +gulp.task("gen-index-hassio-prod", async () => { + const latestManifest = require(path.resolve( + paths.hassio_output_latest, + "manifest.json" + )); + const es5Manifest = require(path.resolve( + paths.hassio_output_es5, + "manifest.json" + )); + writeHassioEntrypoint( + latestManifest["entrypoint.js"], + es5Manifest["entrypoint.js"] + ); +}); + +function writeHassioEntrypoint(latestEntrypoint, es5Entrypoint) { + fs.mkdirSync(paths.hassio_output_root, { recursive: true }); + fs.writeFileSync( + path.resolve(paths.hassio_output_root, "entrypoint.js"), + ` +try { + new Function("import('${paths.hassio_publicPath}/frontend_latest/${latestEntrypoint}')")(); +} catch (err) { + var el = document.createElement('script'); + el.src = '${paths.hassio_publicPath}/frontend_es5/${es5Entrypoint}'; + document.body.appendChild(el); +} + `, + { encoding: "utf-8" } + ); +} diff --git a/build-scripts/gulp/hassio.js b/build-scripts/gulp/hassio.js index 858a58e263..c055ba7685 100644 --- a/build-scripts/gulp/hassio.js +++ b/build-scripts/gulp/hassio.js @@ -11,24 +11,6 @@ require("./webpack.js"); require("./compress.js"); require("./rollup.js"); -async function writeEntrypointJS() { - // We ship two builds and we need to do feature detection on what version to load. - fs.mkdirSync(paths.hassio_output_root, { recursive: true }); - fs.writeFileSync( - path.resolve(paths.hassio_output_root, "entrypoint.js"), - ` -try { - new Function("import('${paths.hassio_publicPath}/frontend_latest/entrypoint.js')")(); -} catch (err) { - var el = document.createElement('script'); - el.src = '${paths.hassio_publicPath}/frontend_es5/entrypoint.js'; - document.body.appendChild(el); -} - `, - { encoding: "utf-8" } - ); -} - gulp.task( "develop-hassio", gulp.series( @@ -37,7 +19,7 @@ gulp.task( }, "clean-hassio", "gen-icons-json", - writeEntrypointJS, + "gen-index-hassio-dev", env.useRollup() ? "rollup-watch-hassio" : "webpack-watch-hassio" ) ); @@ -51,7 +33,7 @@ gulp.task( "clean-hassio", "gen-icons-json", env.useRollup() ? "rollup-prod-hassio" : "webpack-prod-hassio", - writeEntrypointJS, + "gen-index-hassio-prod", ...// Don't compress running tests (env.isTest() ? [] : ["compress-hassio"]) ) diff --git a/build-scripts/paths.js b/build-scripts/paths.js index 0a3e4fe79d..ab1b6d3853 100644 --- a/build-scripts/paths.js +++ b/build-scripts/paths.js @@ -34,6 +34,11 @@ module.exports = { hassio_dir: path.resolve(__dirname, "../hassio"), hassio_output_root: path.resolve(__dirname, "../hassio/build"), + hassio_output_latest: path.resolve( + __dirname, + "../hassio/build/frontend_latest" + ), + hassio_output_es5: path.resolve(__dirname, "../hassio/build/frontend_es5"), hassio_publicPath: "/api/hassio/app", translations_src: path.resolve(__dirname, "../src/translations"),