From e10e7244c6427ace07cd8e19f2bbeb4e2b395103 Mon Sep 17 00:00:00 2001 From: Sean Lynch Date: Wed, 21 Oct 2020 07:38:51 -0400 Subject: [PATCH] Use svelte.config.js's extensions for plugin-svelte input (#1373) * Use svelte.config.js's extensions for plugin-svelte input if available (and not overridden by plugin config) * Update README --- plugins/plugin-svelte/README.md | 2 +- plugins/plugin-svelte/plugin.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/plugin-svelte/README.md b/plugins/plugin-svelte/README.md index 0e23f60a0b..1e21ca7acd 100644 --- a/plugins/plugin-svelte/README.md +++ b/plugins/plugin-svelte/README.md @@ -22,7 +22,7 @@ By default, this plugin will look for a `svelte.config.js` file in your project | Name | Type | Description | | :---------------- | :--------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------ | | `configFilePath` | `string` | Relative path to a Svelte config file. Defaults to load `svelte.config.js` from the current project root directory. | -| `input` | `string[]` | Array of file extensions to process. Defaults to `['.svelte']`. | +| `input` | `string[]` | Array of file extensions to process. Uses `svelte.config.js` `extensions` if available. Defaults to `['.svelte']`. | | `preprocess` | [svelte.preprocess options](https://svelte.dev/docs#svelte_preprocess) | Configure the Svelte pre-processor. If this option is given, the config file `preprocess` option will be ignored. | | `compilerOptions` | [svelte.compile options](https://svelte.dev/docs#svelte_compile) | Configure the Svelte compiler.If this option is given, the config file `preprocess` option will be ignored. | | `hmrOptions` | [svelte-hmr options](https://github.com/rixo/svelte-hmr) | Configure HMR & "fast refresh" behavior for Svelte. | diff --git a/plugins/plugin-svelte/plugin.js b/plugins/plugin-svelte/plugin.js index 5fa9261b57..02525580bd 100644 --- a/plugins/plugin-svelte/plugin.js +++ b/plugins/plugin-svelte/plugin.js @@ -48,13 +48,14 @@ module.exports = function plugin(snowpackConfig, pluginOptions = {}) { let configFilePath = path.resolve(cwd, pluginOptions.configFilePath || 'svelte.config.js'); let compilerOptions = pluginOptions.compilerOptions; let preprocessOptions = pluginOptions.preprocess; - let resolveInputOption = pluginOptions.input || ['.svelte']; + let resolveInputOption = pluginOptions.input; const hmrOptions = pluginOptions.hmrOptions; if (fs.existsSync(configFilePath)) { const configFileConfig = require(configFilePath); preprocessOptions = preprocessOptions || configFileConfig.preprocess; compilerOptions = compilerOptions || configFileConfig.compilerOptions; + resolveInputOption = resolveInputOption || configFileConfig.extensions; } else { //user svelte.config.js is optional and should not error if not configured if (pluginOptions.configFilePath) { @@ -65,7 +66,7 @@ module.exports = function plugin(snowpackConfig, pluginOptions = {}) { return { name: '@snowpack/plugin-svelte', resolve: { - input: resolveInputOption, + input: resolveInputOption || ['.svelte'], output: ['.js', '.css'], }, knownEntrypoints: [