Skip to content

Commit 1e01360

Browse files
committed
core: Svelte 5 work
- use Svelte 4 in repository for testing now - get tests passing using Svelte 5 - Silence Svelte 5 version of unused CSS warning code if `emitCss` is `false`
1 parent 719f351 commit 1e01360

File tree

5 files changed

+524
-51
lines changed

5 files changed

+524
-51
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# rollup-plugin-svelte changelog
22

3+
## 7.2.1
4+
5+
- Silence Svelte 5 version of unused CSS warning code if `emitCss` is `false`
6+
37
## 7.2.0
48

59
- Support compiling `svelte.js/ts` files in Svelte 5

index.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const svelte = require('svelte/compiler');
66

77
const PREFIX = '[rollup-plugin-svelte]';
88

9+
const majorVersion = Number(svelte.VERSION.split('.')[0]);
10+
911
const plugin_options = new Set([
1012
'emitCss',
1113
'exclude',
@@ -26,7 +28,7 @@ module.exports = function (options = {}) {
2628
const extensions = rest.extensions || ['.svelte'];
2729
const filter = createFilter(rest.include, rest.exclude);
2830

29-
if (svelte.VERSION[0] === '3') {
31+
if (majorVersion === 3) {
3032
compilerOptions.format = 'esm';
3133
}
3234

@@ -42,8 +44,7 @@ module.exports = function (options = {}) {
4244
const { onwarn, emitCss = true } = rest;
4345

4446
if (emitCss) {
45-
const [majorVer] = svelte.VERSION.split('.');
46-
const cssOptionValue = majorVer > 3 ? 'external' : false;
47+
const cssOptionValue = majorVersion > 3 ? 'external' : false;
4748
if (compilerOptions.css) {
4849
console.warn(
4950
`${PREFIX} Forcing \`"compilerOptions.css": ${
@@ -129,10 +130,7 @@ module.exports = function (options = {}) {
129130
async transform(code, id) {
130131
if (!filter(id)) return null;
131132

132-
if (
133-
Number(svelte.VERSION.split('.')[0]) >= 5 &&
134-
(id.endsWith('.svelte.js') || id.endsWith('.svelte.ts'))
135-
) {
133+
if (majorVersion > 4 && (id.endsWith('.svelte.js') || id.endsWith('.svelte.ts'))) {
136134
const compiled = svelte.compileModule(code, {
137135
filename: id,
138136
dev: compilerOptions.dev,
@@ -164,9 +162,18 @@ module.exports = function (options = {}) {
164162
const compiled = svelte.compile(code, svelte_options);
165163

166164
(compiled.warnings || []).forEach((warning) => {
167-
if (!emitCss && warning.code === 'css-unused-selector') return;
168-
if (onwarn) onwarn(warning, this.warn);
169-
else this.warn(warning);
165+
if (
166+
!emitCss &&
167+
(warning.code === 'css-unused-selector' || warning.code === 'css_unused_selector')
168+
) {
169+
return;
170+
}
171+
172+
if (onwarn) {
173+
onwarn(warning, this.warn);
174+
} else {
175+
this.warn(warning);
176+
}
170177
});
171178

172179
if (emitCss && compiled.css && compiled.css.code) {

0 commit comments

Comments
 (0)