1
- const { basename , extname , relative } = require ( 'path' ) ;
1
+ const { relative } = require ( 'path' ) ;
2
2
const { getOptions } = require ( 'loader-utils' ) ;
3
3
4
4
const hotApi = require . resolve ( './lib/hot-api.js' ) ;
5
5
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' ) ;
11
7
12
8
const pluginOptions = {
13
9
externalDependencies : true ,
@@ -52,19 +48,6 @@ function posixify(file) {
52
48
return file . replace ( / [ / \\ ] / g, '/' ) ;
53
49
}
54
50
55
- function sanitize ( input ) {
56
- return basename ( input )
57
- . replace ( extname ( input ) , '' )
58
- . replace ( / [ ^ a - z A - 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
-
68
51
function normalize ( compiled ) {
69
52
// svelte.compile signature changed in 1.60 — this avoids
70
53
// future deprecation warnings while preserving backwards
@@ -116,19 +99,11 @@ module.exports = function(source, map) {
116
99
117
100
const compileOptions = {
118
101
filename : this . resourcePath ,
119
- format : options . format || ( major_version >= 3 ? 'esm' : 'es' )
102
+ format : options . format || 'esm'
120
103
} ;
121
104
122
105
const handleWarning = warning => this . emitWarning ( new Error ( warning ) ) ;
123
106
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
-
132
107
for ( const option in options ) {
133
108
if ( ! pluginOptions [ option ] ) compileOptions [ option ] = options [ option ] ;
134
109
}
@@ -147,13 +122,11 @@ module.exports = function(source, map) {
147
122
148
123
let { js, css, warnings } = normalize ( compile ( processed . toString ( ) , compileOptions ) ) ;
149
124
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
+ ) ;
157
130
158
131
if ( options . hotReload && ! isProduction && ! isServer ) {
159
132
const hotOptions = Object . assign ( { } , options . hotOptions ) ;
0 commit comments