Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

processString() returns identical string #642

Open
braebo opened this issue Apr 5, 2021 · 0 comments
Open

processString() returns identical string #642

braebo opened this issue Apr 5, 2021 · 0 comments

Comments

@braebo
Copy link

braebo commented Apr 5, 2021

Hey guys!

I'm trying to explore a custom solution for combing the style tags in .svelte files. It seems to work so far, but the processString() function returns an identical string.

My implementation reads as follows:

import { readFile } from 'fs/promises';
import Comb from 'csscomb/lib/core';
import path from 'path';

const testFile = '../src/routes/news/index.svelte';
const defaultFile = path.join(__dirname, testFile);

const combcss = async (file = defaultFile) => {
	
	const data = await readFile(file);
	const source = data.toString('utf8');
	
	const doc = new DOMParser().parseFromString(source, "text/html");
	
	const CSS = [...doc.querySelectorAll('style')]
		.map(style => style.textContent).toString();
	console.log(CSS);
         // 👆 outputs: h1 { color: white; text-align: center; padding-top: 50vh; width: 100%; position: relative; font-size: 4rem; }
	
	const comb = new Comb()
	comb.configure(require('./csscomb.json'))

	const filename = path.basename(file)
	
	const combedCSS = await comb.processString(CSS, {context: 'stylesheet', filename, syntax: 'css'});
	console.log(combedCSS);
         // 👆also outputs: h1 { color: white; text-align: center; padding-top: 50vh; width: 100%; position: relative; font-size: 4rem; }
};

try { combcss() } catch (e) { console.error(e) }

When I console.log(comb), I can see that it is indeed recieving the config. Everything also works if I simply make a .css file and run npx csscomb scripts/comb.css --config scripts/csscomb.json

I'm wondering if there's something obvious I'm missing in order to get back the processed string? I'm hoping once I have that, I can just write it back to the .svelte file.

Anyways- thanks for such an awesome tool!! I'm excited to be able to use it in .svelte files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant