Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warn on missing svelte condition #225

Merged
merged 5 commits into from
Feb 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { relative } = require('path');
const path = require('path');
const { getOptions } = require('loader-utils');
const { buildMakeHot } = require('./lib/make-hot.js');
const { compile, preprocess } = require('svelte/compiler');
Expand All @@ -10,6 +10,28 @@ function posixify(file) {
const virtualModules = new Map();
let index = 0;

let configFile = 'webpack.config.js';
for (let i = 0; i < process.argv.length; i++) {
if (process.argv[i] === '--config') {
configFile = process.argv[i + 1];
break;
}

if (process.argv[i].startsWith('--config=')) {
configFile = process.argv[i].split('=')[1];
break;
}
}

try {
const config = require(path.resolve(process.cwd(), configFile));
if (!config.resolve || !config.resolve.conditionNames || !config.resolve.conditionNames.includes('svelte')) {
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');
}
} catch (e) {
// do nothing and hope for the best
}

module.exports = function(source, map) {
this.cacheable();

Expand Down Expand Up @@ -64,7 +86,7 @@ module.exports = function(source, map) {
if (options.hotReload && !isProduction && !isServer) {
const hotOptions = { ...options.hotOptions };
const makeHot = buildMakeHot(hotOptions);
const id = JSON.stringify(relative(process.cwd(), compileOptions.filename));
const id = JSON.stringify(path.relative(process.cwd(), compileOptions.filename));
js.code = makeHot(id, js.code, hotOptions, compiled, source, compileOptions);
}

Expand Down