Skip to content

Commit

Permalink
Use svelte.config.js's extensions for plugin-svelte input (#1373)
Browse files Browse the repository at this point in the history
* Use svelte.config.js's extensions for plugin-svelte input if available (and not overridden by plugin config)

* Update README
  • Loading branch information
techniq authored Oct 21, 2020
1 parent d90a1fb commit e10e724
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugins/plugin-svelte/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
5 changes: 3 additions & 2 deletions plugins/plugin-svelte/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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: [
Expand Down

1 comment on commit e10e724

@vercel
Copy link

@vercel vercel bot commented on e10e724 Oct 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.