diff --git a/examples/.prettierrc b/examples/.prettierrc
index 1745ccd..b40f64a 100644
--- a/examples/.prettierrc
+++ b/examples/.prettierrc
@@ -3,9 +3,10 @@
"tabWidth": 4,
"trailingComma": "all",
"singleQuote": true,
- "jsxBracketSameLine": true,
+ "bracketSameLine": true,
"semi": true,
"importOrder": ["^@server/(.*)$", "^@core/(.*)$", "^@ui/(.*)$", "^[./]"],
"importOrderSeparation": true,
- "importOrderSortSpecifiers": true
+ "importOrderSortSpecifiers": true,
+ "plugins": ["../lib/src/index.js"]
}
diff --git a/examples/example.svelte b/examples/example.svelte
new file mode 100644
index 0000000..526fb1b
--- /dev/null
+++ b/examples/example.svelte
@@ -0,0 +1,48 @@
+
+
+
+ Hello Svelte!
+ The count is {count}
+
+
+
+
diff --git a/src/index.ts b/src/index.ts
index 0afcba6..4647619 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -6,10 +6,12 @@ import { parsers as typescriptParsers } from 'prettier/plugins/typescript';
import { defaultPreprocessor } from './preprocessors/default-processor';
import { sveltePreprocessor } from './preprocessors/svelte-preprocessor';
import { vuePreprocessor } from './preprocessors/vue-preprocessor';
+import type { Options } from 'prettier';
+import { createSvelteParsers } from './utils/create-svelte-parsers';
-const { parsers: svelteParsers } = require('prettier-plugin-svelte');
+const svelteParsers = createSvelteParsers();
-const options = {
+const options: Options = {
importOrder: {
type: 'path',
category: 'Global',
@@ -62,7 +64,7 @@ const options = {
category: 'Global',
default: 'with',
description: 'Provide a keyword for import attributes',
- }
+ },
};
module.exports = {
@@ -84,7 +86,7 @@ module.exports = {
preprocess: vuePreprocessor,
},
svelte: {
- ...svelteParsers.svelte,
+ ...svelteParsers.parsers.svelte,
preprocess: sveltePreprocessor,
},
},
diff --git a/src/utils/create-svelte-parsers.ts b/src/utils/create-svelte-parsers.ts
new file mode 100644
index 0000000..1c72863
--- /dev/null
+++ b/src/utils/create-svelte-parsers.ts
@@ -0,0 +1,8 @@
+export function createSvelteParsers() {
+ try {
+ var { parsers } = require('prettier-plugin-svelte');
+ } catch {
+ return {};
+ }
+ return { parsers };
+}
\ No newline at end of file