Skip to content

Commit

Permalink
fix: rollup minify selectors should retain spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
radium-v committed Jul 17, 2020
1 parent a0b8658 commit 16b3c45
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const spaceBetweenTags = /(>)\s+(<)/g;
const spaceBetweenAttrs = /(["'\w])(?!\s*>)\s+/g;
const openEnded = /(?:[^="'\w])?(["'\w])\s*$/g;

export default function transformHTMLFragment(data) {
export function transformHTMLFragment(data) {
// if the chunk is only space, collapse and return it
if (data.match(onlySpace)) {
return data.replace(onlySpace, " ");
Expand All @@ -25,3 +25,18 @@ export default function transformHTMLFragment(data) {

return data.trim();
}

const separators = /\s*([\{\};])\s*/gm;
const lastProp = /;\s*(\})/gm;
const endingSpaces = / ?\s+$/gm;

export function transformCSSFragment(data) {
// Remove extra space, but not too much
data = data.replace(separators, "$1");

// Remove semicolons followed by property list end
data = data.replace(lastProp, "$1");

// space might be between property values or between selectors
return data.replace(endingSpaces, " ");
}
19 changes: 14 additions & 5 deletions packages/web-components/fast-components-msft/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import commonJS from "rollup-plugin-commonjs";
import filesize from "rollup-plugin-filesize";
import minifyTaggedCSSTemplate from "rollup-plugin-minify-tagged-css-template";
import transformTaggedTemplate from "rollup-plugin-transform-tagged-template";
import resolve from "rollup-plugin-node-resolve";
import { terser } from "rollup-plugin-terser";
import transformTaggedTemplate from "rollup-plugin-transform-tagged-template";
import typescript from "rollup-plugin-typescript2";
import transformHTMLFragment from "../../../build/transform-html-fragment";
import {
transformCSSFragment,
transformHTMLFragment,
} from "../../../build/transform-fragments";

const parserOptions = { sourceType: "module" };
const parserOptions = {
sourceType: "module",
};

export default [
{
Expand All @@ -33,14 +37,19 @@ export default [
},
},
}),
minifyTaggedCSSTemplate({ parserOptions }),
transformTaggedTemplate({
tagsToProcess: ["css"],
transformer: transformCSSFragment,
parserOptions,
}),
transformTaggedTemplate({
tagsToProcess: ["html"],
transformer: transformHTMLFragment,
parserOptions,
}),
filesize({
showMinifiedSize: false,
showBrotliSize: true,
}),
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const ProgressStyles = css`
height: 100%;
background-color: ${accentForegroundRestBehavior.var};
border-radius: calc(var(--design-unit) * 1px);
animation-timing-function: cubic-bezier(0.4, 0.0, 0.6, 1.0);
animation-timing-function: cubic-bezier(0.4, 0, 0.6, 1);
width: 40%;
animation: indeterminate-1 2s infinite;
}
Expand All @@ -59,12 +59,13 @@ export const ProgressStyles = css`
height: 100%;
background-color: ${accentForegroundRestBehavior.var};
border-radius: calc(var(--design-unit) * 1px);
animation-timing-function: cubic-bezier(0.4, 0.0, 0.6, 1.0);
animation-timing-function: cubic-bezier(0.4, 0, 0.6, 1);
width: 60%;
animation: indeterminate-2 2s infinite;
}
:host(.paused) .indeterminate-indicator-1, :host(.paused) .indeterminate-indicator-2 {
:host(.paused) .indeterminate-indicator-1,
:host(.paused) .indeterminate-indicator-2 {
animation-play-state: paused;
background-color: ${neutralFillRestBehavior.var};
}
Expand All @@ -88,7 +89,7 @@ export const ProgressStyles = css`
100% {
opacity: 0;
transform: translateX(300%);
},
}
}
@keyframes indeterminate-2 {
Expand All @@ -106,8 +107,8 @@ export const ProgressStyles = css`
100% {
transform: translateX(166.66%);
opacity: 1;
},
},
}
}
`.withBehaviors(
accentForegroundRestBehavior,
neutralFillRestBehavior,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ import {
} from "../styles";

export const SliderStyles = css`
:host([hidden]) {
display: none;
}
${display("inline-grid")} :host {
--thumb-size: calc(${heightNumber} * 0.5);
--thumb-translate: calc(var(--thumb-size) * 0.5);
Expand Down Expand Up @@ -57,7 +53,7 @@ export const SliderStyles = css`
position: absolute;
height: calc(var(--thumb-size) * 1px);
width: calc(var(--thumb-size) * 1px);
transition: "all 0.2s ease";
transition: all 0.2s ease;
}
.thumb-cursor {
border: none;
Expand Down
21 changes: 16 additions & 5 deletions packages/web-components/fast-components/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import commonJS from "rollup-plugin-commonjs";
import filesize from "rollup-plugin-filesize";
import minifyTaggedCSSTemplate from "rollup-plugin-minify-tagged-css-template";
import resolve from "rollup-plugin-node-resolve";
import { terser } from "rollup-plugin-terser";
import transformTaggedTemplate from "rollup-plugin-transform-tagged-template";
import typescript from "rollup-plugin-typescript2";
import transformHTMLFragment from "../../../build/transform-html-fragment";
import {
transformCSSFragment,
transformHTMLFragment,
} from "../../../build/transform-fragments";

const parserOptions = { sourceType: "module" };
const parserOptions = {
sourceType: "module",
};

export default [
{
Expand All @@ -33,13 +37,20 @@ export default [
},
},
}),
minifyTaggedCSSTemplate({ parserOptions }),
transformTaggedTemplate({
tagsToProcess: ["css"],
transformer: transformCSSFragment,
parserOptions,
}),
transformTaggedTemplate({
tagsToProcess: ["html"],
transformer: transformHTMLFragment,
parserOptions,
}),
filesize({ showMinifiedSize: false }),
filesize({
showMinifiedSize: false,
showBrotliSize: true,
}),
],
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const ProgressStyles = css`
height: 100%;
background-color: ${accentForegroundRestBehavior.var};
border-radius: calc(var(--design-unit) * 1px);
animation-timing-function: cubic-bezier(0.4, 0.0, 0.6, 1.0);
animation-timing-function: cubic-bezier(0.4, 0, 0.6, 1);
width: 40%;
animation: indeterminate-1 2s infinite;
}
Expand All @@ -59,12 +59,13 @@ export const ProgressStyles = css`
height: 100%;
background-color: ${accentForegroundRestBehavior.var};
border-radius: calc(var(--design-unit) * 1px);
animation-timing-function: cubic-bezier(0.4, 0.0, 0.6, 1.0);
animation-timing-function: cubic-bezier(0.4, 0, 0.6, 1);
width: 60%;
animation: indeterminate-2 2s infinite;
}
:host(.paused) .indeterminate-indicator-1, :host(.paused) .indeterminate-indicator-2 {
:host(.paused) .indeterminate-indicator-1,
:host(.paused) .indeterminate-indicator-2 {
animation-play-state: paused;
background-color: ${neutralFillRestBehavior.var};
}
Expand All @@ -88,7 +89,7 @@ export const ProgressStyles = css`
100% {
opacity: 0;
transform: translateX(300%);
},
}
}
@keyframes indeterminate-2 {
Expand All @@ -106,8 +107,8 @@ export const ProgressStyles = css`
100% {
transform: translateX(166.66%);
opacity: 1;
},
},
}
}
`.withBehaviors(
accentForegroundRestBehavior,
neutralFillRestBehavior,
Expand Down
28 changes: 23 additions & 5 deletions packages/web-components/fast-element/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import commonJS from "rollup-plugin-commonjs";
import filesize from "rollup-plugin-filesize";
import minifyTaggedCSSTemplate from "rollup-plugin-minify-tagged-css-template";
import resolve from "rollup-plugin-node-resolve";
import { terser } from "rollup-plugin-terser";
import transformTaggedTemplate from "rollup-plugin-transform-tagged-template";
import typescript from "rollup-plugin-typescript2";
import {
transformCSSFragment,
transformHTMLFragment,
} from "../../../build/transform-fragments";

const parserOptions = {
sourceType: "module",
};

export default [
{
Expand All @@ -18,20 +28,28 @@ export default [
},
],
plugins: [
resolve(),
commonJS(),
typescript({
tsconfigOverride: {
compilerOptions: {
declaration: false,
},
},
}),
minifyTaggedCSSTemplate({
parserOptions: {
sourceType: "module",
},
transformTaggedTemplate({
tagsToProcess: ["css"],
transformer: transformCSSFragment,
parserOptions,
}),
transformTaggedTemplate({
tagsToProcess: ["html"],
transformer: transformHTMLFragment,
parserOptions,
}),
filesize({
showMinifiedSize: false,
showBrotliSize: true,
}),
],
},
Expand Down
17 changes: 13 additions & 4 deletions packages/web-components/fast-foundation/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import commonJS from "rollup-plugin-commonjs";
import filesize from "rollup-plugin-filesize";
import minifyTaggedCSSTemplate from "rollup-plugin-minify-tagged-css-template";
import resolve from "rollup-plugin-node-resolve";
import { terser } from "rollup-plugin-terser";
import transformTaggedTemplate from "rollup-plugin-transform-tagged-template";
import typescript from "rollup-plugin-typescript2";
import transformHTMLFragment from "../../../build/transform-html-fragment";
import {
transformCSSFragment,
transformHTMLFragment,
} from "../../../build/transform-fragments";

const parserOptions = { sourceType: "module" };
const parserOptions = {
sourceType: "module",
};

export default [
{
Expand All @@ -33,14 +37,19 @@ export default [
},
},
}),
minifyTaggedCSSTemplate({ parserOptions }),
transformTaggedTemplate({
tagsToProcess: ["css"],
transformer: transformCSSFragment,
parserOptions,
}),
transformTaggedTemplate({
tagsToProcess: ["html"],
transformer: transformHTMLFragment,
parserOptions,
}),
filesize({
showMinifiedSize: false,
showBrotliSize: true,
}),
],
},
Expand Down

0 comments on commit 16b3c45

Please sign in to comment.