Skip to content

Commit

Permalink
Hash entrypoint to avoid caching
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Jun 17, 2021
1 parent b230c7b commit 455d1bb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
22 changes: 22 additions & 0 deletions build-scripts/rollup/manifest-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default function (userOptions = {}) {
return {
name: "manifest",
generateBundle(outputOptions, bundle) {
const manifest = {};

for (const chunk of Object.values(bundle)) {
if (!chunk.isEntry) {
continue;
}
manifest[chunk.name] = chunk.fileName;
}

this.emitFile({
type: "asset",
source: JSON.stringify(manifest, undefined, 2),
name: "manifest.json",
fileName: "manifest.json",
});
},
};
}
5 changes: 5 additions & 0 deletions raw_package/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
"""ESPHome dashboard."""
from pathlib import Path
import json


def where():
"""Return path to the frontend."""
return Path(__file__).parent

def entrypoint():
manifest = json.loads((where() / "static/js/esphome/manifest.json").read_text())
return manifest['index']
36 changes: 23 additions & 13 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,37 @@ import { nodeResolve } from "@rollup/plugin-node-resolve";
import { terser } from "rollup-plugin-terser";
import json from "@rollup/plugin-json";
import typescript from "@rollup/plugin-typescript";
import manifest from "./build-scripts/rollup/manifest-plugin";

const isProdBuild = process.env.NODE_ENV === "production";

/**
* @type { import("rollup").MergedRollupOptions }
*/
const config = {
input: "src/index.ts",
output: {
dir: "esphome_dashboard/static/js/esphome/",
format: "module",
entryFileNames: isProdBuild ? "[name]-[hash].js" : "[name].js",
chunkFileNames: isProdBuild ? "c.[hash].js" : "[name].js",
assetFileNames: isProdBuild ? "a.[hash].js" : "[name].js",
},
preserveEntrySignatures: false,
plugins: [typescript(), nodeResolve(), json()],
plugins: [
typescript(),
nodeResolve(),
json(),
manifest(),
isProdBuild &&
terser({
ecma: 2019,
toplevel: true,
output: {
comments: false,
},
}),
].filter(Boolean),
};

if (process.env.NODE_ENV === "production") {
config.plugins.push(
terser({
ecma: 2019,
toplevel: true,
output: {
comments: false,
},
})
);
}

export default config;

0 comments on commit 455d1bb

Please sign in to comment.