Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions build-scripts/babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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",
[
require("@babel/plugin-proposal-decorators").default,
{ decoratorsBeforeExport: true },
],
[
require("@babel/plugin-proposal-class-properties").default,
{ loose: true },
],
],
},
},
};
};
24 changes: 20 additions & 4 deletions build-scripts/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const CompressionPlugin = require("compression-webpack-plugin");
const zopfli = require("@gfx/zopfli");
const ManifestPlugin = require("webpack-manifest-plugin");
const paths = require("./paths.js");
const { babelLoaderConfig } = require("./babel.js");

let version = fs
.readFileSync(path.resolve(paths.polymer_dir, "setup.py"), "utf8")
Expand Down Expand Up @@ -42,7 +43,7 @@ const resolve = {

const tsLoader = (latestBuild) => ({
test: /\.ts|tsx$/,
exclude: /node_modules/,
exclude: [path.resolve(paths.polymer_dir, "node_modules")],
use: [
{
loader: "ts-loader",
Expand Down Expand Up @@ -126,12 +127,17 @@ const createAppConfig = ({ isProdBuild, latestBuild, isStatsBuild }) => {
"hass-icons": "./src/entrypoints/hass-icons.ts",
};

const rules = [tsLoader(latestBuild), cssLoader, htmlLoader];
if (!latestBuild) {
rules.push(babelLoaderConfig({ latestBuild }));
}

return {
mode: genMode(isProdBuild),
devtool: genDevTool(isProdBuild),
entry,
module: {
rules: [tsLoader(latestBuild), cssLoader, htmlLoader],
rules,
},
optimization: optimization(latestBuild),
plugins: [
Expand Down Expand Up @@ -191,6 +197,11 @@ const createAppConfig = ({ isProdBuild, latestBuild, isStatsBuild }) => {
};

const createDemoConfig = ({ isProdBuild, latestBuild, isStatsBuild }) => {
const rules = [tsLoader(latestBuild), cssLoader, htmlLoader];
if (!latestBuild) {
rules.push(babelLoaderConfig({ latestBuild }));
}

return {
mode: genMode(isProdBuild),
devtool: genDevTool(isProdBuild),
Expand All @@ -199,7 +210,7 @@ const createDemoConfig = ({ isProdBuild, latestBuild, isStatsBuild }) => {
compatibility: "./src/entrypoints/compatibility.ts",
},
module: {
rules: [tsLoader(latestBuild), cssLoader, htmlLoader],
rules,
},
optimization: optimization(latestBuild),
plugins: [
Expand Down Expand Up @@ -241,12 +252,17 @@ const createCastConfig = ({ isProdBuild, latestBuild }) => {
entry.receiver = "./cast/src/receiver/entrypoint.ts";
}

const rules = [tsLoader(latestBuild), cssLoader, htmlLoader];
if (!latestBuild) {
rules.push(babelLoaderConfig({ latestBuild }));
}

return {
mode: genMode(isProdBuild),
devtool: genDevTool(isProdBuild),
entry,
module: {
rules: [tsLoader(latestBuild), cssLoader, htmlLoader],
rules,
},
optimization: optimization(latestBuild),
plugins: [
Expand Down
70 changes: 41 additions & 29 deletions gallery/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,61 @@
const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const webpackBase = require("../build-scripts/webpack.js");
const { babelLoaderConfig } = require("../build-scripts/babel.js");

const isProd = process.env.NODE_ENV === "production";
const chunkFilename = isProd ? "chunk.[chunkhash].js" : "[name].chunk.js";
const buildPath = path.resolve(__dirname, "dist");
const publicPath = isProd ? "./" : "http://localhost:8080/";
const latestBuild = true;

const rules = [
{
exclude: [path.resolve(__dirname, "../node_modules")],
test: /\.ts$/,
use: [
{
loader: "ts-loader",
options: {
compilerOptions: latestBuild
? { noEmit: false }
: {
target: "es5",
checkJs: false,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this still necessary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope

allowJs: true,
noEmit: false,
},
},
},
],
},
{
test: /\.css$/,
use: "raw-loader",
},
{
test: /\.(html)$/,
use: {
loader: "html-loader",
options: {
exportAsEs6Default: true,
},
},
},
];

if (!latestBuild) {
rules.push(babelLoaderConfig({ latestBuild }));
}

module.exports = {
mode: isProd ? "production" : "development",
// Disabled in prod while we make Home Assistant able to serve the right files.
// Was source-map
devtool: isProd ? "none" : "inline-source-map",
entry: "./src/entrypoint.js",
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
options: {
compilerOptions: latestBuild
? { noEmit: false }
: { target: "es5", noEmit: false },
},
},
],
},
{
test: /\.css$/,
use: "raw-loader",
},
{
test: /\.(html)$/,
use: {
loader: "html-loader",
options: {
exportAsEs6Default: true,
},
},
},
],
rules,
},
optimization: webpackBase.optimization(latestBuild),
plugins: [
Expand Down
1 change: 1 addition & 0 deletions hassio/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require("path");
module.exports = {
// Target directory for the build.
buildDir: path.resolve(__dirname, "build"),
nodeDir: path.resolve(__dirname, "../node_modules"),
// Path where the Hass.io frontend will be publicly available.
publicPath: "/api/hassio/app",
};
62 changes: 37 additions & 25 deletions hassio/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,56 @@ const zopfli = require("@gfx/zopfli");

const config = require("./config.js");
const webpackBase = require("../build-scripts/webpack.js");
const { babelLoaderConfig } = require("../build-scripts/babel.js");

const isProdBuild = process.env.NODE_ENV === "production";
const isCI = process.env.CI === "true";
const chunkFilename = isProdBuild ? "chunk.[chunkhash].js" : "[name].chunk.js";
const latestBuild = false;

const rules = [
{
exclude: [config.nodeDir],
test: /\.ts$/,
use: [
{
loader: "ts-loader",
options: {
compilerOptions: latestBuild
? { noEmit: false }
: {
target: "es5",
checkJs: false,
allowJs: true,
noEmit: false,
},
},
},
],
},
{
test: /\.(html)$/,
use: {
loader: "html-loader",
options: {
exportAsEs6Default: true,
},
},
},
];

if (!latestBuild) {
rules.push(babelLoaderConfig({ latestBuild }));
}

module.exports = {
mode: isProdBuild ? "production" : "development",
devtool: isProdBuild ? "source-map" : "inline-source-map",
entry: {
entrypoint: "./src/entrypoint.js",
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
options: {
compilerOptions: latestBuild
? { noEmit: false }
: { target: "es5", noEmit: false },
},
},
],
},
{
test: /\.(html)$/,
use: {
loader: "html-loader",
options: {
exportAsEs6Default: true,
},
},
},
],
rules,
},
optimization: webpackBase.optimization(latestBuild),
plugins: [
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@
"xss": "^1.0.6"
},
"devDependencies": {
"@babel/core": "^7.4.0",
"@babel/plugin-external-helpers": "^7.2.0",
"@babel/plugin-proposal-class-properties": "^7.4.0",
"@babel/plugin-proposal-decorators": "^7.4.0",
"@babel/plugin-proposal-object-rest-spread": "^7.4.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-transform-react-jsx": "^7.3.0",
"@babel/preset-env": "^7.4.2",
"@babel/preset-typescript": "^7.3.3",
"@gfx/zopfli": "^1.0.11",
"@types/chai": "^4.1.7",
"@types/chromecast-caf-receiver": "^3.0.12",
Expand All @@ -114,6 +123,7 @@
"@types/leaflet": "^1.4.3",
"@types/memoize-one": "4.1.0",
"@types/mocha": "^5.2.6",
"babel-loader": "^8.0.5",
"chai": "^4.2.0",
"compression-webpack-plugin": "^2.0.0",
"copy-webpack-plugin": "^5.0.2",
Expand Down
Loading