Skip to content

Commit e0fbd7d

Browse files
committed
add blank-line-removal plugin
1 parent 5ec316f commit e0fbd7d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

rollup/npmHelpers.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import deepMerge from 'deepmerge';
1010
import {
1111
makeConstToVarPlugin,
1212
makeNodeResolvePlugin,
13+
makeRemoveBlankLinesPlugin,
1314
makeRemoveESLintCommentsPlugin,
1415
makeSucrasePlugin,
1516
} from './plugins/index.js';
@@ -28,6 +29,7 @@ export function makeBaseNPMConfig(options = {}) {
2829
const sucrasePlugin = makeSucrasePlugin();
2930
const constToVarPlugin = makeConstToVarPlugin();
3031
const removeESLintCommentsPlugin = makeRemoveESLintCommentsPlugin();
32+
const removeBlankLinesPlugin = makeRemoveBlankLinesPlugin();
3133

3234
return {
3335
input: entrypoints,
@@ -68,7 +70,7 @@ export function makeBaseNPMConfig(options = {}) {
6870
interop: esModuleInterop ? 'auto' : 'esModule',
6971
},
7072

71-
plugins: [nodeResolvePlugin, sucrasePlugin, constToVarPlugin, removeESLintCommentsPlugin],
73+
plugins: [nodeResolvePlugin, sucrasePlugin, constToVarPlugin, removeESLintCommentsPlugin, removeBlankLinesPlugin],
7274

7375
// don't include imported modules from outside the package in the final output
7476
external: [

rollup/plugins/npmPlugins.js

+16
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,19 @@ export function makeRemoveESLintCommentsPlugin() {
8181
],
8282
});
8383
}
84+
85+
/**
86+
* Create a plugin to strip multiple consecutive blank lines, with or without whitespace in them. from the output.
87+
*
88+
* @returns A `rollup-plugin-re` instance.
89+
*/
90+
export function makeRemoveBlankLinesPlugin() {
91+
return regexReplace({
92+
patterns: [
93+
{
94+
test: /\n(\n\s*)+\n/g,
95+
replace: '\n\n',
96+
},
97+
],
98+
});
99+
}

0 commit comments

Comments
 (0)