Skip to content

Commit 77845aa

Browse files
authored
Merge branch 'master' into users/janechu/add-frontpage-to-docs
2 parents cda0871 + 62af44f commit 77845aa

File tree

1 file changed

+40
-17
lines changed
  • sites/website/versioned_docs/version-1.x/integrations

1 file changed

+40
-17
lines changed

sites/website/versioned_docs/version-1.x/integrations/rollup.md

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,38 @@ import copy from 'rollup-plugin-copy';
9999
import serve from 'rollup-plugin-serve';
100100
import { terser } from 'rollup-plugin-terser';
101101

102+
/**
103+
* Reduces extra spaces in HTML tagged templates.
104+
*
105+
* @param {string} data - the fragment value
106+
* @returns string
107+
*/
108+
export function transformHTMLFragment(data) {
109+
data = data.replace(/\s*([<>])\s*/g, '$1'); // remove spaces before and after angle brackets
110+
return data.replace(/\s{2,}/g, ' '); // Collapse all sequences to 1 space
111+
}
112+
113+
/**
114+
* Reduces extra spaces in CSS tagged templates.
115+
*
116+
* Breakdown of this regex:
117+
* (?:\s*\/\*(?:.|\s)+?\*\/\s*) Remove comments (non-capturing)
118+
* (?:;)\s+(?=\}) Remove semicolons and spaces followed by property list end (non-capturing)
119+
* \s+(?=\{) Remove spaces before property list start (non-capturing)
120+
* (?<=:)\s+ Remove spaces after property declarations (non-capturing)
121+
* \s*([{};,])\s* Remove extra spaces before and after braces, semicolons, and commas (captures)
122+
*
123+
* @param {string} data - the fragment value
124+
* @returns string
125+
*/
126+
export function transformCSSFragment(data) {
127+
return data.replace(/(?:\s*\/\*(?:.|\s)+?\*\/\s*)|(?:;)\s+(?=\})|\s+(?=\{)|(?<=:)\s+|\s*([{};,])\s*/g, '$1');
128+
}
129+
130+
const parserOptions = {
131+
sourceType: 'module',
132+
};
133+
102134
export default {
103135
input: 'src/main.ts',
104136
output: {
@@ -109,23 +141,14 @@ export default {
109141
},
110142
plugins: [
111143
transformTaggedTemplate({
112-
tagsToProcess: ['html','css'],
113-
parserOptions: {
114-
sourceType: "module",
115-
plugins: [
116-
"typescript",
117-
[
118-
"decorators",
119-
{ decoratorsBeforeExport: true }
120-
]
121-
]
122-
},
123-
transformer(data) {
124-
data = data.replace(/\s([{}()>~+=^$:!;])\s/gm, '$1');
125-
data = data.replace(/([",[]])\s+/gm, '$1');
126-
data = data.replace(/\s{2,}/gm, ' ');
127-
return data.trim();
128-
}
144+
tagsToProcess: ['css'],
145+
transformer: transformCSSFragment,
146+
parserOptions,
147+
}),
148+
transformTaggedTemplate({
149+
tagsToProcess: ['html'],
150+
transformer: transformHTMLFragment,
151+
parserOptions,
129152
}),
130153
typescript(),
131154
resolve(),

0 commit comments

Comments
 (0)