Skip to content

Commit e6c22b1

Browse files
authored
Merge pull request #22 from rollup/gh-17
squelch css warnings if css: false
2 parents 5e67f2b + c856408 commit e6c22b1

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ export default function svelte(options = {}) {
184184
const compiled = compile(
185185
code,
186186
Object.assign({}, {
187-
onwarn: warning => this.warn(warning),
187+
onwarn: warning => {
188+
// TODO replace this with warning.code, post sveltejs/svelte#824
189+
if (options.css === false && warning.message === 'Unused CSS selector') return;
190+
this.warn(warning);
191+
},
188192
onerror: error => this.error(error)
189193
}, fixedOptions, {
190194
name: capitalize(sanitize(id)),

test/test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,24 @@ describe('rollup-plugin-svelte', () => {
112112
});
113113
});
114114
});
115+
116+
it('squelches CSS warnings if css: false', () => {
117+
const { transform } = plugin({
118+
css: false,
119+
cascade: false
120+
});
121+
122+
transform.call({
123+
warn: warning => {
124+
throw new Error(warning.message);
125+
}
126+
}, `
127+
<div></div>
128+
<style>
129+
.unused {
130+
color: red;
131+
}
132+
</style>
133+
`, 'test.html');
134+
});
115135
});

0 commit comments

Comments
 (0)