Skip to content

Commit a08f67e

Browse files
committed
add eslint-comment-stripping plugin
1 parent 7679e30 commit a08f67e

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

rollup/npmHelpers.js

+8-2
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
input: entrypoints,
@@ -62,7 +68,7 @@ export function makeBaseNPMConfig(options = {}) {
6268
interop: esModuleInterop ? 'auto' : 'esModule',
6369
},
6470

65-
plugins: [nodeResolvePlugin, sucrasePlugin, constToVarPlugin],
71+
plugins: [nodeResolvePlugin, sucrasePlugin, constToVarPlugin, removeESLintCommentsPlugin],
6672

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

rollup/plugins/npmPlugins.js

+20
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)