This commit is contained in:
Paulus Schoutsen 2020-05-23 00:06:23 -07:00 committed by GitHub
parent 7e281f66c2
commit ad386c0e22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 193 additions and 140 deletions

View File

@ -1,31 +0,0 @@
module.exports.options = ({ latestBuild }) => ({
presets: [
!latestBuild && [require("@babel/preset-env").default, { modules: false }],
require("@babel/preset-typescript").default,
].filter(Boolean),
plugins: [
// Part of ES2018. Converts {...a, b: 2} to Object.assign({}, a, {b: 2})
[
"@babel/plugin-proposal-object-rest-spread",
{ loose: true, useBuiltIns: true },
],
// Only support the syntax, Webpack will handle it.
"@babel/syntax-dynamic-import",
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-nullish-coalescing-operator",
[
require("@babel/plugin-proposal-decorators").default,
{ decoratorsBeforeExport: true },
],
[
require("@babel/plugin-proposal-class-properties").default,
{ loose: true },
],
],
});
// Are already ES5, cause warnings when babelified.
module.exports.exclude = [
require.resolve("@mdi/js/mdi.js"),
require.resolve("hls.js"),
];

View File

@ -3,7 +3,7 @@ const env = require("./env.js");
const paths = require("./paths.js"); const paths = require("./paths.js");
// Files from NPM Packages that should not be imported // Files from NPM Packages that should not be imported
module.exports.ignorePackages = [ module.exports.ignorePackages = ({ latestBuild }) => [
// Bloats bundle and it's not used. // Bloats bundle and it's not used.
path.resolve(require.resolve("moment"), "../locale"), path.resolve(require.resolve("moment"), "../locale"),
// Part of yaml.js and only used for !!js functions that we don't use // Part of yaml.js and only used for !!js functions that we don't use
@ -11,7 +11,7 @@ module.exports.ignorePackages = [
]; ];
// Files from NPM packages that we should replace with empty file // Files from NPM packages that we should replace with empty file
module.exports.emptyPackages = [ module.exports.emptyPackages = ({ latestBuild }) => [
// Contains all color definitions for all material color sets. // Contains all color definitions for all material color sets.
// We don't use it // We don't use it
require.resolve("@polymer/paper-styles/color.js"), require.resolve("@polymer/paper-styles/color.js"),
@ -39,6 +39,39 @@ module.exports.terserOptions = (latestBuild) => ({
output: { comments: false }, output: { comments: false },
}); });
module.exports.babelOptions = ({ latestBuild }) => ({
babelrc: false,
presets: [
!latestBuild && [require("@babel/preset-env").default, { modules: false }],
require("@babel/preset-typescript").default,
].filter(Boolean),
plugins: [
// Part of ES2018. Converts {...a, b: 2} to Object.assign({}, a, {b: 2})
[
"@babel/plugin-proposal-object-rest-spread",
{ loose: true, useBuiltIns: true },
],
// Only support the syntax, Webpack will handle it.
"@babel/syntax-dynamic-import",
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-nullish-coalescing-operator",
[
require("@babel/plugin-proposal-decorators").default,
{ decoratorsBeforeExport: true },
],
[
require("@babel/plugin-proposal-class-properties").default,
{ loose: true },
],
],
});
// Are already ES5, cause warnings when babelified.
module.exports.babelExclude = () => [
require.resolve("@mdi/js/mdi.js"),
require.resolve("hls.js"),
];
const outputPath = (outputRoot, latestBuild) => const outputPath = (outputRoot, latestBuild) =>
path.resolve(outputRoot, latestBuild ? "frontend_latest" : "frontend_es5"); path.resolve(outputRoot, latestBuild ? "frontend_latest" : "frontend_es5");
@ -78,7 +111,7 @@ module.exports.config = {
compatibility: "./src/entrypoints/compatibility.ts", compatibility: "./src/entrypoints/compatibility.ts",
"custom-panel": "./src/entrypoints/custom-panel.ts", "custom-panel": "./src/entrypoints/custom-panel.ts",
}, },
outputPath: outputPath(paths.root, latestBuild), outputPath: outputPath(paths.app_output_root, latestBuild),
publicPath: publicPath(latestBuild), publicPath: publicPath(latestBuild),
isProdBuild, isProdBuild,
latestBuild, latestBuild,
@ -95,7 +128,7 @@ module.exports.config = {
"src/entrypoints/compatibility.ts" "src/entrypoints/compatibility.ts"
), ),
}, },
outputPath: outputPath(paths.demo_root, latestBuild), outputPath: outputPath(paths.demo_output_root, latestBuild),
publicPath: publicPath(latestBuild), publicPath: publicPath(latestBuild),
defineOverlay: { defineOverlay: {
__VERSION__: JSON.stringify(`DEMO-${env.version()}`), __VERSION__: JSON.stringify(`DEMO-${env.version()}`),
@ -121,7 +154,7 @@ module.exports.config = {
return { return {
entry, entry,
outputPath: outputPath(paths.cast_root, latestBuild), outputPath: outputPath(paths.cast_output_root, latestBuild),
publicPath: publicPath(latestBuild), publicPath: publicPath(latestBuild),
isProdBuild, isProdBuild,
latestBuild, latestBuild,
@ -139,7 +172,7 @@ module.exports.config = {
entry: { entry: {
entrypoint: path.resolve(paths.hassio_dir, "src/entrypoint.ts"), entrypoint: path.resolve(paths.hassio_dir, "src/entrypoint.ts"),
}, },
outputPath: paths.hassio_root, outputPath: paths.hassio_output_root,
publicPath: paths.hassio_publicPath, publicPath: paths.hassio_publicPath,
isProdBuild, isProdBuild,
latestBuild, latestBuild,
@ -152,7 +185,7 @@ module.exports.config = {
entry: { entry: {
entrypoint: path.resolve(paths.gallery_dir, "src/entrypoint.js"), entrypoint: path.resolve(paths.gallery_dir, "src/entrypoint.js"),
}, },
outputPath: outputPath(paths.gallery_root, latestBuild), outputPath: outputPath(paths.gallery_output_root, latestBuild),
publicPath: publicPath(latestBuild), publicPath: publicPath(latestBuild),
isProdBuild, isProdBuild,
latestBuild, latestBuild,

View File

@ -6,34 +6,34 @@ require("./translations");
gulp.task( gulp.task(
"clean", "clean",
gulp.parallel("clean-translations", function cleanOutputAndBuildDir() { gulp.parallel("clean-translations", function cleanOutputAndBuildDir() {
return del([config.root, config.build_dir]); return del([config.app_output_root, config.build_dir]);
}) })
); );
gulp.task( gulp.task(
"clean-demo", "clean-demo",
gulp.parallel("clean-translations", function cleanOutputAndBuildDir() { gulp.parallel("clean-translations", function cleanOutputAndBuildDir() {
return del([config.demo_root, config.build_dir]); return del([config.demo_output_root, config.build_dir]);
}) })
); );
gulp.task( gulp.task(
"clean-cast", "clean-cast",
gulp.parallel("clean-translations", function cleanOutputAndBuildDir() { gulp.parallel("clean-translations", function cleanOutputAndBuildDir() {
return del([config.cast_root, config.build_dir]); return del([config.cast_output_root, config.build_dir]);
}) })
); );
gulp.task( gulp.task(
"clean-hassio", "clean-hassio",
gulp.parallel("clean-translations", function cleanOutputAndBuildDir() { gulp.parallel("clean-translations", function cleanOutputAndBuildDir() {
return del([config.hassio_root, config.build_dir]); return del([config.hassio_output_root, config.build_dir]);
}) })
); );
gulp.task( gulp.task(
"clean-gallery", "clean-gallery",
gulp.parallel("clean-translations", function cleanOutputAndBuildDir() { gulp.parallel("clean-translations", function cleanOutputAndBuildDir() {
return del([config.gallery_root, config.build_dir]); return del([config.gallery_output_root, config.build_dir]);
}) })
); );

View File

@ -8,36 +8,36 @@ const paths = require("../paths");
gulp.task("compress-app", function compressApp() { gulp.task("compress-app", function compressApp() {
const jsLatest = gulp const jsLatest = gulp
.src(path.resolve(paths.output, "**/*.js")) .src(path.resolve(paths.app_output_latest, "**/*.js"))
.pipe(zopfli({ threshold: 150 })) .pipe(zopfli({ threshold: 150 }))
.pipe(gulp.dest(paths.output)); .pipe(gulp.dest(paths.app_output_latest));
const jsEs5 = gulp const jsEs5 = gulp
.src(path.resolve(paths.output_es5, "**/*.js")) .src(path.resolve(paths.app_output_es5, "**/*.js"))
.pipe(zopfli({ threshold: 150 })) .pipe(zopfli({ threshold: 150 }))
.pipe(gulp.dest(paths.output_es5)); .pipe(gulp.dest(paths.app_output_es5));
const polyfills = gulp const polyfills = gulp
.src(path.resolve(paths.static, "polyfills/*.js")) .src(path.resolve(paths.app_output_static, "polyfills/*.js"))
.pipe(zopfli({ threshold: 150 })) .pipe(zopfli({ threshold: 150 }))
.pipe(gulp.dest(path.resolve(paths.static, "polyfills"))); .pipe(gulp.dest(path.resolve(paths.app_output_static, "polyfills")));
const translations = gulp const translations = gulp
.src(path.resolve(paths.static, "translations/**/*.json")) .src(path.resolve(paths.app_output_static, "translations/**/*.json"))
.pipe(zopfli({ threshold: 150 })) .pipe(zopfli({ threshold: 150 }))
.pipe(gulp.dest(path.resolve(paths.static, "translations"))); .pipe(gulp.dest(path.resolve(paths.app_output_static, "translations")));
const icons = gulp const icons = gulp
.src(path.resolve(paths.static, "mdi/*.json")) .src(path.resolve(paths.app_output_static, "mdi/*.json"))
.pipe(zopfli({ threshold: 150 })) .pipe(zopfli({ threshold: 150 }))
.pipe(gulp.dest(path.resolve(paths.static, "mdi"))); .pipe(gulp.dest(path.resolve(paths.app_output_static, "mdi")));
return merge(jsLatest, jsEs5, polyfills, translations, icons); return merge(jsLatest, jsEs5, polyfills, translations, icons);
}); });
gulp.task("compress-hassio", function compressApp() { gulp.task("compress-hassio", function compressApp() {
return gulp return gulp
.src(path.resolve(paths.hassio_root, "**/*.js")) .src(path.resolve(paths.hassio_output_root, "**/*.js"))
.pipe(zopfli()) .pipe(zopfli())
.pipe(gulp.dest(paths.hassio_root)); .pipe(gulp.dest(paths.hassio_output_root));
}); });

View File

@ -57,14 +57,23 @@ gulp.task("gen-pages-dev", (done) => {
es5PageJS: `/frontend_es5/${page}.js`, es5PageJS: `/frontend_es5/${page}.js`,
}); });
fs.outputFileSync(path.resolve(paths.root, `${page}.html`), content); fs.outputFileSync(
path.resolve(paths.app_output_root, `${page}.html`),
content
);
} }
done(); done();
}); });
gulp.task("gen-pages-prod", (done) => { gulp.task("gen-pages-prod", (done) => {
const latestManifest = require(path.resolve(paths.output, "manifest.json")); const latestManifest = require(path.resolve(
const es5Manifest = require(path.resolve(paths.output_es5, "manifest.json")); paths.app_output_latest,
"manifest.json"
));
const es5Manifest = require(path.resolve(
paths.app_output_es5,
"manifest.json"
));
for (const page of PAGES) { for (const page of PAGES) {
const content = renderTemplate(page, { const content = renderTemplate(page, {
@ -75,7 +84,7 @@ gulp.task("gen-pages-prod", (done) => {
}); });
fs.outputFileSync( fs.outputFileSync(
path.resolve(paths.root, `${page}.html`), path.resolve(paths.app_output_root, `${page}.html`),
minifyHtml(content) minifyHtml(content)
); );
} }
@ -96,13 +105,19 @@ gulp.task("gen-index-app-dev", (done) => {
es5CustomPanelJS: "/frontend_es5/custom-panel.js", es5CustomPanelJS: "/frontend_es5/custom-panel.js",
}).replace(/#THEMEC/g, "{{ theme_color }}"); }).replace(/#THEMEC/g, "{{ theme_color }}");
fs.outputFileSync(path.resolve(paths.root, "index.html"), content); fs.outputFileSync(path.resolve(paths.app_output_root, "index.html"), content);
done(); done();
}); });
gulp.task("gen-index-app-prod", (done) => { gulp.task("gen-index-app-prod", (done) => {
const latestManifest = require(path.resolve(paths.output, "manifest.json")); const latestManifest = require(path.resolve(
const es5Manifest = require(path.resolve(paths.output_es5, "manifest.json")); paths.app_output_latest,
"manifest.json"
));
const es5Manifest = require(path.resolve(
paths.app_output_es5,
"manifest.json"
));
const content = renderTemplate("index", { const content = renderTemplate("index", {
latestAppJS: latestManifest["app.js"], latestAppJS: latestManifest["app.js"],
latestCoreJS: latestManifest["core.js"], latestCoreJS: latestManifest["core.js"],
@ -115,7 +130,10 @@ gulp.task("gen-index-app-prod", (done) => {
}); });
const minified = minifyHtml(content).replace(/#THEMEC/g, "{{ theme_color }}"); const minified = minifyHtml(content).replace(/#THEMEC/g, "{{ theme_color }}");
fs.outputFileSync(path.resolve(paths.root, "index.html"), minified); fs.outputFileSync(
path.resolve(paths.app_output_root, "index.html"),
minified
);
done(); done();
}); });
@ -124,7 +142,7 @@ gulp.task("gen-index-cast-dev", (done) => {
latestReceiverJS: "/frontend_latest/receiver.js", latestReceiverJS: "/frontend_latest/receiver.js",
}); });
fs.outputFileSync( fs.outputFileSync(
path.resolve(paths.cast_root, "receiver.html"), path.resolve(paths.cast_output_root, "receiver.html"),
contentReceiver contentReceiver
); );
@ -132,14 +150,17 @@ gulp.task("gen-index-cast-dev", (done) => {
latestLauncherJS: "/frontend_latest/launcher.js", latestLauncherJS: "/frontend_latest/launcher.js",
es5LauncherJS: "/frontend_es5/launcher.js", es5LauncherJS: "/frontend_es5/launcher.js",
}); });
fs.outputFileSync(path.resolve(paths.cast_root, "faq.html"), contentFAQ); fs.outputFileSync(
path.resolve(paths.cast_output_root, "faq.html"),
contentFAQ
);
const contentLauncher = renderCastTemplate("launcher", { const contentLauncher = renderCastTemplate("launcher", {
latestLauncherJS: "/frontend_latest/launcher.js", latestLauncherJS: "/frontend_latest/launcher.js",
es5LauncherJS: "/frontend_es5/launcher.js", es5LauncherJS: "/frontend_es5/launcher.js",
}); });
fs.outputFileSync( fs.outputFileSync(
path.resolve(paths.cast_root, "index.html"), path.resolve(paths.cast_output_root, "index.html"),
contentLauncher contentLauncher
); );
done(); done();
@ -147,7 +168,7 @@ gulp.task("gen-index-cast-dev", (done) => {
gulp.task("gen-index-cast-prod", (done) => { gulp.task("gen-index-cast-prod", (done) => {
const latestManifest = require(path.resolve( const latestManifest = require(path.resolve(
paths.cast_output, paths.cast_output_latest,
"manifest.json" "manifest.json"
)); ));
const es5Manifest = require(path.resolve( const es5Manifest = require(path.resolve(
@ -159,7 +180,7 @@ gulp.task("gen-index-cast-prod", (done) => {
latestReceiverJS: latestManifest["receiver.js"], latestReceiverJS: latestManifest["receiver.js"],
}); });
fs.outputFileSync( fs.outputFileSync(
path.resolve(paths.cast_root, "receiver.html"), path.resolve(paths.cast_output_root, "receiver.html"),
contentReceiver contentReceiver
); );
@ -167,14 +188,17 @@ gulp.task("gen-index-cast-prod", (done) => {
latestLauncherJS: latestManifest["launcher.js"], latestLauncherJS: latestManifest["launcher.js"],
es5LauncherJS: es5Manifest["launcher.js"], es5LauncherJS: es5Manifest["launcher.js"],
}); });
fs.outputFileSync(path.resolve(paths.cast_root, "faq.html"), contentFAQ); fs.outputFileSync(
path.resolve(paths.cast_output_root, "faq.html"),
contentFAQ
);
const contentLauncher = renderCastTemplate("launcher", { const contentLauncher = renderCastTemplate("launcher", {
latestLauncherJS: latestManifest["launcher.js"], latestLauncherJS: latestManifest["launcher.js"],
es5LauncherJS: es5Manifest["launcher.js"], es5LauncherJS: es5Manifest["launcher.js"],
}); });
fs.outputFileSync( fs.outputFileSync(
path.resolve(paths.cast_root, "index.html"), path.resolve(paths.cast_output_root, "index.html"),
contentLauncher contentLauncher
); );
done(); done();
@ -190,13 +214,16 @@ gulp.task("gen-index-demo-dev", (done) => {
es5DemoJS: "/frontend_es5/main.js", es5DemoJS: "/frontend_es5/main.js",
}); });
fs.outputFileSync(path.resolve(paths.demo_root, "index.html"), content); fs.outputFileSync(
path.resolve(paths.demo_output_root, "index.html"),
content
);
done(); done();
}); });
gulp.task("gen-index-demo-prod", (done) => { gulp.task("gen-index-demo-prod", (done) => {
const latestManifest = require(path.resolve( const latestManifest = require(path.resolve(
paths.demo_output, paths.demo_output_latest,
"manifest.json" "manifest.json"
)); ));
const es5Manifest = require(path.resolve( const es5Manifest = require(path.resolve(
@ -211,7 +238,10 @@ gulp.task("gen-index-demo-prod", (done) => {
}); });
const minified = minifyHtml(content); const minified = minifyHtml(content);
fs.outputFileSync(path.resolve(paths.demo_root, "index.html"), minified); fs.outputFileSync(
path.resolve(paths.demo_output_root, "index.html"),
minified
);
done(); done();
}); });
@ -222,13 +252,16 @@ gulp.task("gen-index-gallery-dev", (done) => {
latestGalleryJS: "./frontend_latest/entrypoint.js", latestGalleryJS: "./frontend_latest/entrypoint.js",
}); });
fs.outputFileSync(path.resolve(paths.gallery_root, "index.html"), content); fs.outputFileSync(
path.resolve(paths.gallery_output_root, "index.html"),
content
);
done(); done();
}); });
gulp.task("gen-index-gallery-prod", (done) => { gulp.task("gen-index-gallery-prod", (done) => {
const latestManifest = require(path.resolve( const latestManifest = require(path.resolve(
paths.gallery_output, paths.gallery_output_latest,
"manifest.json" "manifest.json"
)); ));
const content = renderGalleryTemplate("index", { const content = renderGalleryTemplate("index", {
@ -236,6 +269,9 @@ gulp.task("gen-index-gallery-prod", (done) => {
}); });
const minified = minifyHtml(content); const minified = minifyHtml(content);
fs.outputFileSync(path.resolve(paths.gallery_root, "index.html"), minified); fs.outputFileSync(
path.resolve(paths.gallery_output_root, "index.html"),
minified
);
done(); done();
}); });

View File

@ -79,14 +79,14 @@ function copyMapPanel(staticDir) {
} }
gulp.task("copy-translations-app", async () => { gulp.task("copy-translations-app", async () => {
const staticDir = paths.static; const staticDir = paths.app_output_static;
copyTranslations(staticDir); copyTranslations(staticDir);
}); });
gulp.task("copy-static-app", async () => { gulp.task("copy-static-app", async () => {
const staticDir = paths.static; const staticDir = paths.app_output_static;
// Basic static files // Basic static files
fs.copySync(polyPath("public"), paths.root); fs.copySync(polyPath("public"), paths.app_output_root);
copyLoaderJS(staticDir); copyLoaderJS(staticDir);
copyPolyfills(staticDir); copyPolyfills(staticDir);
@ -102,41 +102,44 @@ gulp.task("copy-static-demo", async () => {
// Copy app static files // Copy app static files
fs.copySync( fs.copySync(
polyPath("public/static"), polyPath("public/static"),
path.resolve(paths.demo_root, "static") path.resolve(paths.demo_output_root, "static")
); );
// Copy demo static files // Copy demo static files
fs.copySync(path.resolve(paths.demo_dir, "public"), paths.demo_root); fs.copySync(path.resolve(paths.demo_dir, "public"), paths.demo_output_root);
copyLoaderJS(paths.demo_static); copyLoaderJS(paths.demo_output_static);
copyPolyfills(paths.demo_static); copyPolyfills(paths.demo_output_static);
copyMapPanel(paths.demo_static); copyMapPanel(paths.demo_output_static);
copyFonts(paths.demo_static); copyFonts(paths.demo_output_static);
copyTranslations(paths.demo_static); copyTranslations(paths.demo_output_static);
copyMdiIcons(paths.demo_static); copyMdiIcons(paths.demo_output_static);
}); });
gulp.task("copy-static-cast", async () => { gulp.task("copy-static-cast", async () => {
// Copy app static files // Copy app static files
fs.copySync(polyPath("public/static"), paths.cast_static); fs.copySync(polyPath("public/static"), paths.cast_output_static);
// Copy cast static files // Copy cast static files
fs.copySync(path.resolve(paths.cast_dir, "public"), paths.cast_root); fs.copySync(path.resolve(paths.cast_dir, "public"), paths.cast_output_root);
copyLoaderJS(paths.cast_static); copyLoaderJS(paths.cast_output_static);
copyPolyfills(paths.cast_static); copyPolyfills(paths.cast_output_static);
copyMapPanel(paths.cast_static); copyMapPanel(paths.cast_output_static);
copyFonts(paths.cast_static); copyFonts(paths.cast_output_static);
copyTranslations(paths.cast_static); copyTranslations(paths.cast_output_static);
copyMdiIcons(paths.cast_static); copyMdiIcons(paths.cast_output_static);
}); });
gulp.task("copy-static-gallery", async () => { gulp.task("copy-static-gallery", async () => {
// Copy app static files // Copy app static files
fs.copySync(polyPath("public/static"), paths.gallery_static); fs.copySync(polyPath("public/static"), paths.gallery_output_static);
// Copy gallery static files // Copy gallery static files
fs.copySync(path.resolve(paths.gallery_dir, "public"), paths.gallery_root); fs.copySync(
path.resolve(paths.gallery_dir, "public"),
paths.gallery_output_root
);
copyMapPanel(paths.gallery_static); copyMapPanel(paths.gallery_output_static);
copyFonts(paths.gallery_static); copyFonts(paths.gallery_output_static);
copyTranslations(paths.gallery_static); copyTranslations(paths.gallery_output_static);
copyMdiIcons(paths.gallery_static); copyMdiIcons(paths.gallery_output_static);
}); });

View File

@ -95,14 +95,14 @@ gulp.task("rollup-watch-hassio", () => {
gulp.task("rollup-dev-server-demo", () => { gulp.task("rollup-dev-server-demo", () => {
watchRollup(rollupConfig.createDemoConfig, ["demo/src"], { watchRollup(rollupConfig.createDemoConfig, ["demo/src"], {
root: paths.demo_root, root: paths.demo_output_root,
port: 8090, port: 8090,
}); });
}); });
gulp.task("rollup-dev-server-cast", () => { gulp.task("rollup-dev-server-cast", () => {
watchRollup(rollupConfig.createCastConfig, ["cast/src"], { watchRollup(rollupConfig.createCastConfig, ["cast/src"], {
root: paths.cast_root, root: paths.cast_output_root,
port: 8080, port: 8080,
networkAccess: true, networkAccess: true,
}); });
@ -110,7 +110,7 @@ gulp.task("rollup-dev-server-cast", () => {
gulp.task("rollup-dev-server-gallery", () => { gulp.task("rollup-dev-server-gallery", () => {
watchRollup(rollupConfig.createGalleryConfig, ["gallery/src"], { watchRollup(rollupConfig.createGalleryConfig, ["gallery/src"], {
root: paths.gallery_root, root: paths.gallery_output_root,
port: 8100, port: 8100,
}); });
}); });

View File

@ -9,7 +9,7 @@ const workboxBuild = require("workbox-build");
const sourceMapUrl = require("source-map-url"); const sourceMapUrl = require("source-map-url");
const paths = require("../paths.js"); const paths = require("../paths.js");
const swDest = path.resolve(paths.root, "service_worker.js"); const swDest = path.resolve(paths.app_output_root, "service_worker.js");
const writeSW = (content) => fs.outputFileSync(swDest, content.trim() + "\n"); const writeSW = (content) => fs.outputFileSync(swDest, content.trim() + "\n");
@ -31,32 +31,38 @@ self.addEventListener('install', (event) => {
gulp.task("gen-service-worker-app-prod", async () => { gulp.task("gen-service-worker-app-prod", async () => {
// Read bundled source file // Read bundled source file
const bundleManifestLatest = require(path.resolve( const bundleManifestLatest = require(path.resolve(
paths.output, paths.app_output_latest,
"manifest.json" "manifest.json"
)); ));
let serviceWorkerContent = fs.readFileSync( let serviceWorkerContent = fs.readFileSync(
paths.root + bundleManifestLatest["service_worker.js"], paths.app_output_root + bundleManifestLatest["service_worker.js"],
"utf-8" "utf-8"
); );
// Delete old file from frontend_latest so manifest won't pick it up // Delete old file from frontend_latest so manifest won't pick it up
fs.removeSync(paths.root + bundleManifestLatest["service_worker.js"]); fs.removeSync(
fs.removeSync(paths.root + bundleManifestLatest["service_worker.js.map"]); paths.app_output_root + bundleManifestLatest["service_worker.js"]
);
fs.removeSync(
paths.app_output_root + bundleManifestLatest["service_worker.js.map"]
);
// Remove ES5 // Remove ES5
const bundleManifestES5 = require(path.resolve( const bundleManifestES5 = require(path.resolve(
paths.output_es5, paths.app_output_es5,
"manifest.json" "manifest.json"
)); ));
fs.removeSync(paths.root + bundleManifestES5["service_worker.js"]); fs.removeSync(paths.app_output_root + bundleManifestES5["service_worker.js"]);
fs.removeSync(paths.root + bundleManifestES5["service_worker.js.map"]); fs.removeSync(
paths.app_output_root + bundleManifestES5["service_worker.js.map"]
);
const workboxManifest = await workboxBuild.getManifest({ const workboxManifest = await workboxBuild.getManifest({
// Files that mach this pattern will be considered unique and skip revision check // Files that mach this pattern will be considered unique and skip revision check
// ignore JS files + translation files // ignore JS files + translation files
dontCacheBustURLsMatching: /(frontend_latest\/.+|static\/translations\/.+)/, dontCacheBustURLsMatching: /(frontend_latest\/.+|static\/translations\/.+)/,
globDirectory: paths.root, globDirectory: paths.app_output_root,
globPatterns: [ globPatterns: [
"frontend_latest/*.js", "frontend_latest/*.js",
// Cache all English translations because we catch them as fallback // Cache all English translations because we catch them as fallback

View File

@ -82,7 +82,7 @@ gulp.task(
gulp.task("webpack-dev-server-demo", () => { gulp.task("webpack-dev-server-demo", () => {
runDevServer({ runDevServer({
compiler: webpack(bothBuilds(createDemoConfig, { isProdBuild: false })), compiler: webpack(bothBuilds(createDemoConfig, { isProdBuild: false })),
contentBase: paths.demo_root, contentBase: paths.demo_output_root,
port: 8090, port: 8090,
}); });
}); });
@ -103,7 +103,7 @@ gulp.task(
gulp.task("webpack-dev-server-cast", () => { gulp.task("webpack-dev-server-cast", () => {
runDevServer({ runDevServer({
compiler: webpack(bothBuilds(createCastConfig, { isProdBuild: false })), compiler: webpack(bothBuilds(createCastConfig, { isProdBuild: false })),
contentBase: paths.cast_root, contentBase: paths.cast_output_root,
port: 8080, port: 8080,
// Accessible from the network, because that's how Cast hits it. // Accessible from the network, because that's how Cast hits it.
listenHost: "0.0.0.0", listenHost: "0.0.0.0",
@ -152,7 +152,7 @@ gulp.task("webpack-dev-server-gallery", () => {
runDevServer({ runDevServer({
// We don't use the es5 build, but the dev server will fuck up the publicPath if we don't // We don't use the es5 build, but the dev server will fuck up the publicPath if we don't
compiler: webpack(bothBuilds(createGalleryConfig, { isProdBuild: false })), compiler: webpack(bothBuilds(createGalleryConfig, { isProdBuild: false })),
contentBase: paths.gallery_root, contentBase: paths.gallery_output_root,
port: 8100, port: 8100,
}); });
}); });

View File

@ -4,30 +4,36 @@ module.exports = {
polymer_dir: path.resolve(__dirname, ".."), polymer_dir: path.resolve(__dirname, ".."),
build_dir: path.resolve(__dirname, "../build"), build_dir: path.resolve(__dirname, "../build"),
root: path.resolve(__dirname, "../hass_frontend"), app_output_root: path.resolve(__dirname, "../hass_frontend"),
static: path.resolve(__dirname, "../hass_frontend/static"), app_output_static: path.resolve(__dirname, "../hass_frontend/static"),
output: path.resolve(__dirname, "../hass_frontend/frontend_latest"), app_output_latest: path.resolve(
output_es5: path.resolve(__dirname, "../hass_frontend/frontend_es5"), __dirname,
"../hass_frontend/frontend_latest"
),
app_output_es5: path.resolve(__dirname, "../hass_frontend/frontend_es5"),
demo_dir: path.resolve(__dirname, "../demo"), demo_dir: path.resolve(__dirname, "../demo"),
demo_root: path.resolve(__dirname, "../demo/dist"), demo_output_root: path.resolve(__dirname, "../demo/dist"),
demo_static: path.resolve(__dirname, "../demo/dist/static"), demo_output_static: path.resolve(__dirname, "../demo/dist/static"),
demo_output: path.resolve(__dirname, "../demo/dist/frontend_latest"), demo_output_latest: path.resolve(__dirname, "../demo/dist/frontend_latest"),
demo_output_es5: path.resolve(__dirname, "../demo/dist/frontend_es5"), demo_output_es5: path.resolve(__dirname, "../demo/dist/frontend_es5"),
cast_dir: path.resolve(__dirname, "../cast"), cast_dir: path.resolve(__dirname, "../cast"),
cast_root: path.resolve(__dirname, "../cast/dist"), cast_output_root: path.resolve(__dirname, "../cast/dist"),
cast_static: path.resolve(__dirname, "../cast/dist/static"), cast_output_static: path.resolve(__dirname, "../cast/dist/static"),
cast_output: path.resolve(__dirname, "../cast/dist/frontend_latest"), cast_output_latest: path.resolve(__dirname, "../cast/dist/frontend_latest"),
cast_output_es5: path.resolve(__dirname, "../cast/dist/frontend_es5"), cast_output_es5: path.resolve(__dirname, "../cast/dist/frontend_es5"),
gallery_dir: path.resolve(__dirname, "../gallery"), gallery_dir: path.resolve(__dirname, "../gallery"),
gallery_root: path.resolve(__dirname, "../gallery/dist"), gallery_output_root: path.resolve(__dirname, "../gallery/dist"),
gallery_output: path.resolve(__dirname, "../gallery/dist/frontend_latest"), gallery_output_latest: path.resolve(
gallery_static: path.resolve(__dirname, "../gallery/dist/static"), __dirname,
"../gallery/dist/frontend_latest"
),
gallery_output_static: path.resolve(__dirname, "../gallery/dist/static"),
hassio_dir: path.resolve(__dirname, "../hassio"), hassio_dir: path.resolve(__dirname, "../hassio"),
hassio_root: path.resolve(__dirname, "../hassio/build"), hassio_output_root: path.resolve(__dirname, "../hassio/build"),
hassio_publicPath: "/api/hassio/app/", hassio_publicPath: "/api/hassio/app/",
translations_src: path.resolve(__dirname, "../src/translations"), translations_src: path.resolve(__dirname, "../src/translations"),

View File

@ -12,7 +12,6 @@ const manifest = require("./rollup-plugins/manifest-plugin");
const worker = require("./rollup-plugins/worker-plugin"); const worker = require("./rollup-plugins/worker-plugin");
const dontHashPlugin = require("./rollup-plugins/dont-hash-plugin"); const dontHashPlugin = require("./rollup-plugins/dont-hash-plugin");
const babelConfig = require("./babel");
const bundle = require("./bundle"); const bundle = require("./bundle");
const extensions = [".js", ".ts"]; const extensions = [".js", ".ts"];
@ -40,7 +39,9 @@ const createRollupConfig = ({
// Some entry points contain no JavaScript. This setting silences a warning about that. // Some entry points contain no JavaScript. This setting silences a warning about that.
// https://rollupjs.org/guide/en/#preserveentrysignatures // https://rollupjs.org/guide/en/#preserveentrysignatures
preserveEntrySignatures: false, preserveEntrySignatures: false,
external: bundle.ignorePackages + bundle.emptyPackages, external:
bundle.ignorePackages({ latestBuild }) +
bundle.emptyPackages({ latestBuild }),
plugins: [ plugins: [
resolve({ extensions, preferBuiltins: false, browser: true }), resolve({ extensions, preferBuiltins: false, browser: true }),
commonjs({ commonjs({
@ -50,10 +51,9 @@ const createRollupConfig = ({
}), }),
json(), json(),
babel({ babel({
...babelConfig.options({ latestBuild }), ...bundle.babelOptions({ latestBuild }),
extensions, extensions,
babelrc: false, exclude: bundle.babelExclude(),
exclude: babelConfig.exclude,
}), }),
string({ string({
// Import certain extensions as strings // Import certain extensions as strings

View File

@ -4,7 +4,6 @@ const TerserPlugin = require("terser-webpack-plugin");
const ManifestPlugin = require("webpack-manifest-plugin"); const ManifestPlugin = require("webpack-manifest-plugin");
const WorkerPlugin = require("worker-plugin"); const WorkerPlugin = require("worker-plugin");
const paths = require("./paths.js"); const paths = require("./paths.js");
const babel = require("./babel.js");
const bundle = require("./bundle"); const bundle = require("./bundle");
const createWebpackConfig = ({ const createWebpackConfig = ({
@ -20,6 +19,7 @@ const createWebpackConfig = ({
if (!dontHash) { if (!dontHash) {
dontHash = new Set(); dontHash = new Set();
} }
const ignorePackages = bundle.ignorePackages({ latestBuild });
return { return {
mode: isProdBuild ? "production" : "development", mode: isProdBuild ? "production" : "development",
devtool: isProdBuild devtool: isProdBuild
@ -31,10 +31,10 @@ const createWebpackConfig = ({
rules: [ rules: [
{ {
test: /\.js$|\.ts$/, test: /\.js$|\.ts$/,
exclude: babel.exclude, exclude: bundle.babelExclude(),
use: { use: {
loader: "babel-loader", loader: "babel-loader",
options: babel.options({ latestBuild }), options: bundle.babelOptions({ latestBuild }),
}, },
}, },
{ {
@ -84,13 +84,13 @@ const createWebpackConfig = ({
throw err; throw err;
} }
return bundle.ignorePackages.some((toIgnorePath) => return ignorePackages.some((toIgnorePath) =>
fullPath.startsWith(toIgnorePath) fullPath.startsWith(toIgnorePath)
); );
}, },
}), }),
new webpack.NormalModuleReplacementPlugin( new webpack.NormalModuleReplacementPlugin(
new RegExp(bundle.emptyPackages.join("|")), new RegExp(bundle.emptyPackages({ latestBuild }).join("|")),
path.resolve(paths.polymer_dir, "src/util/empty.js") path.resolve(paths.polymer_dir, "src/util/empty.js")
), ),
], ],