Skip to content

Commit

Permalink
Experimental svelte config
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Oct 23, 2024
1 parent 571355d commit 7140dd3
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion frontend/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,51 @@
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
// import path from "node:path";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";

// function addComponentIdPreprocessor() {
// return {
// markup: ({ content, filename }) => {
// // Get the component name from the filename
// const componentName = path.basename(filename, '.svelte').toLowerCase();

// // Skip processing if the file contains svelte:options
// if (content.includes('<svelte:options')) {
// console.log('Skipping svelte:options file:', filename);
// return { code: content };
// }

// // Enhanced regex to catch more component patterns
// const regex = /<(?!svelte:)([a-zA-Z][a-zA-Z0-9]*(?:\.[a-zA-Z][a-zA-Z0-9]*)*)[^>]*?(?:>|\s)/;
// const match = content.match(regex);

// if (match) {
// const originalTag = match[0];
// const tagEnd = originalTag.endsWith('>') ? '>' : ' ';

// // Check if the tag already has an id attribute
// if (!originalTag.includes('id=')) {
// // Handle cases where the tag might have other attributes
// let newTag;
// if (originalTag.includes(' ')) {
// // If there are other attributes, insert ID before them
// newTag = originalTag.replace(/^<([^\s>]+)/, `<$1 id="${componentName}"`);
// } else {
// // If it's a simple tag, add the ID
// newTag = originalTag.replace(/>$/, ` id="${componentName}">`);
// }

// console.log('Original:', originalTag);
// console.log('Modified:', newTag);

// return {
// code: content.replace(originalTag, newTag)
// };
// }
// }

// return { code: content };
// }
// };
// }

export default {
preprocess: [vitePreprocess()],
Expand Down

0 comments on commit 7140dd3

Please sign in to comment.