From aa685c715a3519e10b977bc865e35edd6fd744cf Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 15 Feb 2023 16:51:37 -0500 Subject: [PATCH 1/5] warn on missing svelte condition --- index.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 77f6244c..cedec0ad 100644 --- a/index.js +++ b/index.js @@ -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'); @@ -10,6 +10,28 @@ function posixify(file) { const virtualModules = new Map(); let index = 0; +let config_file = 'webpack.config.js'; +for (let i = 0; i < process.argv.length; i++) { + if (process.argv[i] === '--config') { + config_file = process.argv[i + 1]; + break; + } + + if (process.argv[i].startsWith('--config=')) { + config_file = process.argv[i].split('=')[1]; + break; + } +} + +try { + const config = require(path.resolve(process.cwd(), config_file)); + if (!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.\u001B[39m\u001B[22m\n'); + } +} catch { + // do nothing and hope for the best +} + module.exports = function(source, map) { this.cacheable(); @@ -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); } From 62725b1873af7eee0e17e8b9c38d95c8d5cfe223 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 15 Feb 2023 16:54:55 -0500 Subject: [PATCH 2/5] party like it's 2017 --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index cedec0ad..f8d151f9 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,7 @@ for (let i = 0; i < process.argv.length; i++) { try { const config = require(path.resolve(process.cwd(), config_file)); - if (!config.resolve?.conditionNames?.includes('svelte')) { + 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.\u001B[39m\u001B[22m\n'); } } catch { From f825e81f61598d6ece8f75b39b0c85e3e6bcacae Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 15 Feb 2023 17:01:32 -0500 Subject: [PATCH 3/5] this library has not yet been converted to the church_of_snake_case --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index f8d151f9..10a2246f 100644 --- a/index.js +++ b/index.js @@ -10,21 +10,21 @@ function posixify(file) { const virtualModules = new Map(); let index = 0; -let config_file = 'webpack.config.js'; +let configFile = 'webpack.config.js'; for (let i = 0; i < process.argv.length; i++) { if (process.argv[i] === '--config') { - config_file = process.argv[i + 1]; + configFile = process.argv[i + 1]; break; } if (process.argv[i].startsWith('--config=')) { - config_file = process.argv[i].split('=')[1]; + configFile = process.argv[i].split('=')[1]; break; } } try { - const config = require(path.resolve(process.cwd(), config_file)); + 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.\u001B[39m\u001B[22m\n'); } From d710d6f88bc8b90426f5385d59e1a376a79489e4 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 15 Feb 2023 17:01:55 -0500 Subject: [PATCH 4/5] man i have forgotten how to write ancient javascript --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 10a2246f..50816535 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ try { 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.\u001B[39m\u001B[22m\n'); } -} catch { +} catch (e) { // do nothing and hope for the best } From 5c535b455257a6187eb55611577691d8e033e10b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 15 Feb 2023 17:03:01 -0500 Subject: [PATCH 5/5] link to existing docs --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 50816535..8a5485ba 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,7 @@ for (let i = 0; i < process.argv.length; i++) { 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.\u001B[39m\u001B[22m\n'); + 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