mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-09 02:16:35 +00:00
Introduce object rest spread (#1763)
This commit is contained in:
parent
2f6595bca7
commit
3949b47e51
34
config/babel.js
Normal file
34
config/babel.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
module.exports.babelLoaderConfig = ({ latestBuild }) => {
|
||||||
|
if (latestBuild === undefined) {
|
||||||
|
throw Error("latestBuild not defined for babel loader config");
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
test: /\.m?js$/,
|
||||||
|
use: {
|
||||||
|
loader: "babel-loader",
|
||||||
|
options: {
|
||||||
|
presets: [
|
||||||
|
!latestBuild && [
|
||||||
|
require("@babel/preset-env").default,
|
||||||
|
{ modules: false },
|
||||||
|
],
|
||||||
|
].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/transform-react-jsx",
|
||||||
|
{
|
||||||
|
pragma: "h",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
@ -1,6 +1,7 @@
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
|
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
|
||||||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||||
|
const { babelLoaderConfig } = require("../config/babel.js");
|
||||||
|
|
||||||
const isProd = process.env.NODE_ENV === "production";
|
const isProd = process.env.NODE_ENV === "production";
|
||||||
const chunkFilename = isProd ? "chunk.[chunkhash].js" : "[name].chunk.js";
|
const chunkFilename = isProd ? "chunk.[chunkhash].js" : "[name].chunk.js";
|
||||||
@ -15,24 +16,7 @@ module.exports = {
|
|||||||
entry: "./src/entrypoint.js",
|
entry: "./src/entrypoint.js",
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
babelLoaderConfig({ latestBuild: true }),
|
||||||
test: /\.js$/,
|
|
||||||
use: {
|
|
||||||
loader: "babel-loader",
|
|
||||||
options: {
|
|
||||||
plugins: [
|
|
||||||
// Only support the syntax, Webpack will handle it.
|
|
||||||
"@babel/syntax-dynamic-import",
|
|
||||||
[
|
|
||||||
"@babel/transform-react-jsx",
|
|
||||||
{
|
|
||||||
pragma: "h",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
test: /\.(html)$/,
|
test: /\.(html)$/,
|
||||||
use: {
|
use: {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
|
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
|
||||||
const CompressionPlugin = require("compression-webpack-plugin");
|
const CompressionPlugin = require("compression-webpack-plugin");
|
||||||
const config = require("./config.js");
|
const config = require("./config.js");
|
||||||
|
const { babelLoaderConfig } = require("../config/babel.js");
|
||||||
|
|
||||||
const isProdBuild = process.env.NODE_ENV === "production";
|
const isProdBuild = process.env.NODE_ENV === "production";
|
||||||
const chunkFilename = isProdBuild ? "chunk.[chunkhash].js" : "[name].chunk.js";
|
const chunkFilename = isProdBuild ? "chunk.[chunkhash].js" : "[name].chunk.js";
|
||||||
@ -13,21 +14,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
babelLoaderConfig({ latestBuild: false }),
|
||||||
test: /\.m?js$/,
|
|
||||||
use: {
|
|
||||||
loader: "babel-loader",
|
|
||||||
options: {
|
|
||||||
presets: [
|
|
||||||
[require("@babel/preset-env").default, { modules: false }],
|
|
||||||
],
|
|
||||||
plugins: [
|
|
||||||
// Only support the syntax, Webpack will handle it.
|
|
||||||
"@babel/syntax-dynamic-import",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
test: /\.(html)$/,
|
test: /\.(html)$/,
|
||||||
use: {
|
use: {
|
||||||
|
@ -91,6 +91,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.1.2",
|
"@babel/core": "^7.1.2",
|
||||||
"@babel/plugin-external-helpers": "^7.0.0",
|
"@babel/plugin-external-helpers": "^7.0.0",
|
||||||
|
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
|
||||||
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
|
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
|
||||||
"@babel/plugin-transform-react-jsx": "^7.0.0",
|
"@babel/plugin-transform-react-jsx": "^7.0.0",
|
||||||
"@babel/preset-env": "^7.1.0",
|
"@babel/preset-env": "^7.1.0",
|
||||||
|
@ -37,7 +37,7 @@ class HuiEntitiesCard extends PolymerElement {
|
|||||||
this._element = null;
|
this._element = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const card = "card" in config ? Object.assign({}, config.card) : {};
|
const card = "card" in config ? { ...config.card } : {};
|
||||||
if (!card.type) card.type = "entities";
|
if (!card.type) card.type = "entities";
|
||||||
card.entities = [];
|
card.entities = [];
|
||||||
|
|
||||||
@ -66,9 +66,7 @@ class HuiEntitiesCard extends PolymerElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.style.display = "block";
|
this.style.display = "block";
|
||||||
element.setConfig(
|
element.setConfig({ ...element._filterRawConfig, entities: entitiesList });
|
||||||
Object.assign({}, element._filterRawConfig, { entities: entitiesList })
|
|
||||||
);
|
|
||||||
element.isPanel = this.isPanel;
|
element.isPanel = this.isPanel;
|
||||||
element.hass = this.hass;
|
element.hass = this.hass;
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ class HuiGaugeCard extends EventsMixin(PolymerElement) {
|
|||||||
setConfig(config) {
|
setConfig(config) {
|
||||||
if (!config || !config.entity)
|
if (!config || !config.entity)
|
||||||
throw new Error("Invalid card configuration");
|
throw new Error("Invalid card configuration");
|
||||||
this._config = Object.assign({ min: 0, max: 100 }, config);
|
this._config = { min: 0, max: 100, ...config };
|
||||||
}
|
}
|
||||||
|
|
||||||
_computeStateObj(states, entityId) {
|
_computeStateObj(states, entityId) {
|
||||||
|
@ -154,11 +154,7 @@ class HuiGlanceCard extends LocalizeMixin(EventsMixin(LitElement)) {
|
|||||||
break;
|
break;
|
||||||
case "call-service": {
|
case "call-service": {
|
||||||
const [domain, service] = config.service.split(".", 2);
|
const [domain, service] = config.service.split(".", 2);
|
||||||
const serviceData = Object.assign(
|
const serviceData = { entity_id: entityId, ...config.service_data };
|
||||||
{},
|
|
||||||
{ entity_id: entityId },
|
|
||||||
config.service_data
|
|
||||||
);
|
|
||||||
this.hass.callService(domain, service, serviceData);
|
this.hass.callService(domain, service, serviceData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -37,17 +37,15 @@ class HuiSensorCard extends EventsMixin(LitElement) {
|
|||||||
throw new Error("Specify an entity from within the sensor domain.");
|
throw new Error("Specify an entity from within the sensor domain.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const cardConfig = Object.assign(
|
const cardConfig = {
|
||||||
{
|
icon: false,
|
||||||
icon: false,
|
hours_to_show: 24,
|
||||||
hours_to_show: 24,
|
accuracy: 10,
|
||||||
accuracy: 10,
|
height: 100,
|
||||||
height: 100,
|
line_width: 5,
|
||||||
line_width: 5,
|
line_color: "var(--accent-color)",
|
||||||
line_color: "var(--accent-color)",
|
...config,
|
||||||
},
|
};
|
||||||
config
|
|
||||||
);
|
|
||||||
cardConfig.hours_to_show = Number(cardConfig.hours_to_show);
|
cardConfig.hours_to_show = Number(cardConfig.hours_to_show);
|
||||||
cardConfig.accuracy = Number(cardConfig.accuracy);
|
cardConfig.accuracy = Number(cardConfig.accuracy);
|
||||||
cardConfig.height = Number(cardConfig.height);
|
cardConfig.height = Number(cardConfig.height);
|
||||||
|
@ -8,6 +8,7 @@ const CompressionPlugin = require("compression-webpack-plugin");
|
|||||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||||
const zopfli = require("@gfx/zopfli");
|
const zopfli = require("@gfx/zopfli");
|
||||||
const translationMetadata = require("./build-translations/translationMetadata.json");
|
const translationMetadata = require("./build-translations/translationMetadata.json");
|
||||||
|
const { babelLoaderConfig } = require("./config/babel.js");
|
||||||
|
|
||||||
const version = fs.readFileSync("setup.py", "utf8").match(/\d{8}[^']*/);
|
const version = fs.readFileSync("setup.py", "utf8").match(/\d{8}[^']*/);
|
||||||
if (!version) {
|
if (!version) {
|
||||||
@ -61,30 +62,7 @@ function createConfig(isProdBuild, latestBuild) {
|
|||||||
entry,
|
entry,
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
babelLoaderConfig({ latestBuild }),
|
||||||
test: /\.m?js$/,
|
|
||||||
use: {
|
|
||||||
loader: "babel-loader",
|
|
||||||
options: {
|
|
||||||
presets: [
|
|
||||||
!latestBuild && [
|
|
||||||
require("@babel/preset-env").default,
|
|
||||||
{ modules: false },
|
|
||||||
],
|
|
||||||
].filter(Boolean),
|
|
||||||
plugins: [
|
|
||||||
// Only support the syntax, Webpack will handle it.
|
|
||||||
"@babel/syntax-dynamic-import",
|
|
||||||
[
|
|
||||||
"@babel/transform-react-jsx",
|
|
||||||
{
|
|
||||||
pragma: "h",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
test: /\.(html)$/,
|
test: /\.(html)$/,
|
||||||
use: {
|
use: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user