Skip to content

Commit 7710e68

Browse files
committed
add eslint-comment-stripping plugin
1 parent da16300 commit 7710e68

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

rollup/npmHelpers.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import * as path from 'path';
77

88
import deepMerge from 'deepmerge';
99

10-
import { makeConstToVarPlugin, makeNodeResolvePlugin, makeSucrasePlugin } from './plugins/index.js';
10+
import {
11+
makeConstToVarPlugin,
12+
makeNodeResolvePlugin,
13+
makeRemoveESLintCommentsPlugin,
14+
makeSucrasePlugin,
15+
} from './plugins/index.js';
1116

1217
const packageDotJSON = require(path.resolve(process.cwd(), './package.json'));
1318

@@ -22,6 +27,7 @@ export function makeBaseNPMConfig(options = {}) {
2227
const nodeResolvePlugin = makeNodeResolvePlugin();
2328
const sucrasePlugin = makeSucrasePlugin();
2429
const constToVarPlugin = makeConstToVarPlugin();
30+
const removeESLintCommentsPlugin = makeRemoveESLintCommentsPlugin();
2531

2632
// return {
2733
const config = {
@@ -63,7 +69,7 @@ export function makeBaseNPMConfig(options = {}) {
6369
interop: esModuleInterop ? 'auto' : 'esModule',
6470
},
6571

66-
plugins: [nodeResolvePlugin, sucrasePlugin, constToVarPlugin],
72+
plugins: [nodeResolvePlugin, sucrasePlugin, constToVarPlugin, removeESLintCommentsPlugin],
6773

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

rollup/plugins/npmPlugins.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
/**
2+
* Regex Replace plugin docs: https://github.com/jetiny/rollup-plugin-re
23
* Replace plugin docs: https://github.com/rollup/plugins/tree/master/packages/replace
34
* Sucrase plugin docs: https://github.com/rollup/plugins/tree/master/packages/sucrase
45
*/
56

7+
// We need both replacement plugins because one handles regex and the other runs both before and after rollup does its
8+
// bundling work.
9+
import regexReplace from 'rollup-plugin-re';
610
import replace from '@rollup/plugin-replace';
711
import sucrase from '@rollup/plugin-sucrase';
812

@@ -61,3 +65,19 @@ export function makeDebuggerPlugin(hookName) {
6165
},
6266
};
6367
}
68+
69+
/**
70+
* Create a plugin to strip eslint-style comments from the output.
71+
*
72+
* @returns A `rollup-plugin-re` instance.
73+
*/
74+
export function makeRemoveESLintCommentsPlugin() {
75+
return regexReplace({
76+
patterns: [
77+
{
78+
test: /\/[/*] eslint-disable.*\n/g,
79+
replace: '',
80+
},
81+
],
82+
});
83+
}

0 commit comments

Comments
 (0)