diff --git a/babel-plugin-css-template.js b/babel-plugin-css-template.js new file mode 100644 index 00000000..e5f59dad --- /dev/null +++ b/babel-plugin-css-template.js @@ -0,0 +1,31 @@ +/****************************************************************************** + * + * Copyright (c) 2020, the Regular Table Authors. + * + * This file is part of the Regular Table library, distributed under the terms + * of the Apache License 2.0. The full license can be found in the LICENSE + * file. + * + */ + +const fs = require("fs"); + +// Replace whitespace in `html` tagged literals for minification. +module.exports = function (babel) { + const t = babel.types; + return { + visitor: { + TaggedTemplateExpression(path) { + const node = path.node; + if (t.isIdentifier(node.tag, {name: "css"})) { + for (const type of ["raw", "cooked"]) { + for (const element of node.quasi.quasis) { + const value = element.value[type]; + element.value[type] = fs.readFileSync(value).toString(); + } + } + } + }, + }, + }; +}; diff --git a/babel-plugin-transform-tagged-literal.js b/babel-plugin-html-template.js similarity index 100% rename from babel-plugin-transform-tagged-literal.js rename to babel-plugin-html-template.js diff --git a/babel.config.js b/babel.config.js index 93bc5781..5eea811f 100644 --- a/babel.config.js +++ b/babel.config.js @@ -4,17 +4,21 @@ module.exports = { "@babel/preset-env", { targets: { - esmodules: true, + chrome: "70", + node: "12", + ios: "13", }, + useBuiltIns: "usage", + corejs: 3, }, ], ], plugins: [ - "lodash", ["@babel/plugin-proposal-decorators", {legacy: true}], "transform-custom-element-classes", "@babel/plugin-proposal-class-properties", "@babel/plugin-proposal-optional-chaining", - "./babel-plugin-transform-tagged-literal.js", + "./babel-plugin-html-template.js", + "./babel-plugin-css-template.js", ], }; diff --git a/examples/perspective.html b/examples/perspective.html index ad3cea42..2baf1f6c 100644 --- a/examples/perspective.html +++ b/examples/perspective.html @@ -14,6 +14,7 @@ +
@@ -21,13 +22,8 @@