Skip to content

Commit

Permalink
1.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanchuan committed Jul 27, 2024
1 parent 434a320 commit 24cd651
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.8.1

* Add `configFile` option to read `preprocess` from `svelte.config.js`. (#43 by @gengns)

## 1.8.0

* Update peer dependency to support SK >= 1.0.0.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ export default {
// node_modules is ignored by default
exclude: ['**/node_modules/**'],

// if reading svelte.config.js to get preprocesses
configFile: true

}),

sveltekit()
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sveltekit-autoimport",
"version": "1.8.0",
"version": "1.8.1",
"description": "Automatically detect and import components or modules",
"main": "src/index.js",
"scripts": {
Expand Down
20 changes: 11 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,17 @@ export default function autoImport({ components, module, mapping, include, exclu
...plugins.slice(indexPluginSvelte + 1)
];
}
if (!configFile) return;
try {
let dirname = path.dirname(fileURLToPath(import.meta.url));
let relative = path.relative(dirname, config.inlineConfig.root || config.root);
let configFile = path.join(relative, './svelte.config.js');
let pkg = await import(normalizePath('./' + configFile));
preprocess = pkg.default.preprocess || [];
} catch(e) {
console.warn('Error reading svelte.config.js');
// Try reading preprocess from svelte.config.js
if (configFile) {
try {
let dirname = path.dirname(fileURLToPath(import.meta.url));
let relative = path.relative(dirname, config.inlineConfig.root || config.root);
let configFile = path.join(relative, './svelte.config.js');
let pkg = await import(normalizePath('./' + configFile));
preprocess = pkg.default.preprocess || [];
} catch(e) {
console.warn('Error reading svelte.config.js');
}
}
},

Expand Down

0 comments on commit 24cd651

Please sign in to comment.