Skip to content

Commit 8958820

Browse files
authored
Merge pull request #225 from sveltejs/warn-on-missing-svelte-condition
warn on missing svelte condition
2 parents b9466d2 + 5c535b4 commit 8958820

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

index.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { relative } = require('path');
1+
const path = require('path');
22
const { getOptions } = require('loader-utils');
33
const { buildMakeHot } = require('./lib/make-hot.js');
44
const { compile, preprocess } = require('svelte/compiler');
@@ -10,6 +10,28 @@ function posixify(file) {
1010
const virtualModules = new Map();
1111
let index = 0;
1212

13+
let configFile = 'webpack.config.js';
14+
for (let i = 0; i < process.argv.length; i++) {
15+
if (process.argv[i] === '--config') {
16+
configFile = process.argv[i + 1];
17+
break;
18+
}
19+
20+
if (process.argv[i].startsWith('--config=')) {
21+
configFile = process.argv[i].split('=')[1];
22+
break;
23+
}
24+
}
25+
26+
try {
27+
const config = require(path.resolve(process.cwd(), configFile));
28+
if (!config.resolve || !config.resolve.conditionNames || !config.resolve.conditionNames.includes('svelte')) {
29+
console.warn('\n\u001B[1m\u001B[31mWARNING: You should add "svelte" to the "resolve.conditionNames" array in your webpack config. See https://github.com/sveltejs/svelte-loader#resolveconditionnames for more information\u001B[39m\u001B[22m\n');
30+
}
31+
} catch (e) {
32+
// do nothing and hope for the best
33+
}
34+
1335
module.exports = function(source, map) {
1436
this.cacheable();
1537

@@ -64,7 +86,7 @@ module.exports = function(source, map) {
6486
if (options.hotReload && !isProduction && !isServer) {
6587
const hotOptions = { ...options.hotOptions };
6688
const makeHot = buildMakeHot(hotOptions);
67-
const id = JSON.stringify(relative(process.cwd(), compileOptions.filename));
89+
const id = JSON.stringify(path.relative(process.cwd(), compileOptions.filename));
6890
js.code = makeHot(id, js.code, hotOptions, compiled, source, compileOptions);
6991
}
7092

0 commit comments

Comments
 (0)