Skip to content

Commit 185c29b

Browse files
authored
Drop Svelte 2 support (#150)
1 parent fb71641 commit 185c29b

File tree

1 file changed

+8
-35
lines changed

1 file changed

+8
-35
lines changed

index.js

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
const { basename, extname, relative } = require('path');
1+
const { relative } = require('path');
22
const { getOptions } = require('loader-utils');
33

44
const hotApi = require.resolve('./lib/hot-api.js');
55

6-
const { version } = require('svelte/package.json');
7-
const major_version = +version[0];
8-
const { compile, preprocess } = major_version >= 3
9-
? require('svelte/compiler')
10-
: require('svelte');
6+
const { compile, preprocess } = require('svelte/compiler');
117

128
const pluginOptions = {
139
externalDependencies: true,
@@ -52,19 +48,6 @@ function posixify(file) {
5248
return file.replace(/[/\\]/g, '/');
5349
}
5450

55-
function sanitize(input) {
56-
return basename(input)
57-
.replace(extname(input), '')
58-
.replace(/[^a-zA-Z_$0-9]+/g, '_')
59-
.replace(/^_/, '')
60-
.replace(/_$/, '')
61-
.replace(/^(\d)/, '_$1');
62-
}
63-
64-
function capitalize(str) {
65-
return str[0].toUpperCase() + str.slice(1);
66-
}
67-
6851
function normalize(compiled) {
6952
// svelte.compile signature changed in 1.60 — this avoids
7053
// future deprecation warnings while preserving backwards
@@ -116,19 +99,11 @@ module.exports = function(source, map) {
11699

117100
const compileOptions = {
118101
filename: this.resourcePath,
119-
format: options.format || (major_version >= 3 ? 'esm' : 'es')
102+
format: options.format || 'esm'
120103
};
121104

122105
const handleWarning = warning => this.emitWarning(new Error(warning));
123106

124-
if (major_version >= 3) {
125-
// TODO anything?
126-
} else {
127-
compileOptions.shared = options.shared || 'svelte/shared.js';
128-
compileOptions.name = capitalize(sanitize(compileOptions.filename));
129-
compileOptions.onwarn = options.onwarn || handleWarning;
130-
}
131-
132107
for (const option in options) {
133108
if (!pluginOptions[option]) compileOptions[option] = options[option];
134109
}
@@ -147,13 +122,11 @@ module.exports = function(source, map) {
147122

148123
let { js, css, warnings } = normalize(compile(processed.toString(), compileOptions));
149124

150-
if (major_version >= 3) {
151-
warnings.forEach(
152-
options.onwarn
153-
? warning => options.onwarn(warning, handleWarning)
154-
: handleWarning
155-
);
156-
}
125+
warnings.forEach(
126+
options.onwarn
127+
? warning => options.onwarn(warning, handleWarning)
128+
: handleWarning
129+
);
157130

158131
if (options.hotReload && !isProduction && !isServer) {
159132
const hotOptions = Object.assign({}, options.hotOptions);

0 commit comments

Comments
 (0)