Skip to content

Commit 88e00c1

Browse files
authored
Merge pull request #73 from malkomalko/svelte-v3
Get svelte-loader working with v3 alpha
2 parents b3b1001 + 65f02da commit 88e00c1

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
const { basename, extname, relative } = require('path');
2-
const { compile, preprocess } = require('svelte');
32
const { getOptions } = require('loader-utils');
43
const VirtualModules = require('./lib/virtual');
54
const requireRelative = require('require-relative');
65

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

8+
const { version } = require('svelte/package.json');
9+
const major_version = +version[0];
10+
const { compile, preprocess } = major_version >= 3
11+
? require('svelte/compiler')
12+
: require('svelte');
13+
914
function makeHot(id, code, hotOptions) {
1015
const options = JSON.stringify(hotOptions);
1116
const replacement = `
@@ -95,8 +100,14 @@ module.exports = function(source, map) {
95100
const isProduction = this.minimize || process.env.NODE_ENV === 'production';
96101

97102
options.filename = this.resourcePath;
98-
if (!('format' in options)) options.format = 'es';
99-
if (!('shared' in options)) options.shared = options.format === 'es' && requireRelative.resolve('svelte/shared.js', process.cwd());
103+
if (!('format' in options)) {
104+
options.format = major_version >= 3 ? 'esm' : 'es';
105+
}
106+
if (!('shared' in options)) {
107+
const shared = (major_version >= 3 ? 'svelte/internal.js' : 'svelte/shared.js');
108+
options.shared = (options.format === 'es' || options.format === 'esm') &&
109+
requireRelative.resolve(shared, process.cwd());
110+
}
100111
if (!('name' in options)) options.name = capitalize(sanitize(options.filename));
101112
if (!('onwarn' in options)) options.onwarn = warning => this.emitWarning(new Error(warning));
102113
if (options.emitCss) options.css = false;
@@ -134,4 +145,4 @@ module.exports = function(source, map) {
134145
// context when logging to console
135146
callback(new Error(`${err.name}: ${err.toString()}`));
136147
});
137-
};
148+
};

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)