sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.58k stars 1.92k forks source link

CSS sourcemaps are missing #841

Open Rich-Harris opened 3 years ago

Rich-Harris commented 3 years ago

This is really just a placeholder issue to point at https://github.com/vitejs/vite/issues/2830

benmccann commented 3 years ago

We're adding an option in Svelte (https://github.com/sveltejs/svelte/pull/6835) that we will use to disable CSS sourcemaps during SSR by default in vite-plugin-svelte because they're causing issues when using environment variables in Svelte templates (https://github.com/sveltejs/kit/issues/720)

benmccann commented 2 years ago

There's a PR for this: https://github.com/vitejs/vite/pull/7173

alexaisok commented 2 years ago

Just curious what the status of this is - I'm more of a backend developer and don't know much about vite unfortunately. It looks like their PR for enabling sourcemap generation was merged and sveltekit uses a version of vite that has the change. However npm run dev or npm run build in my project don't generate sourcemaps for my CSS/SCSS. Is this expected still?

benmccann commented 2 years ago

You must enable the experimental option: https://vitejs.dev/config/#css-devsourcemap

alexaisok commented 2 years ago

You must enable the experimental option: https://vitejs.dev/config/#css-devsourcemap

Edit Disregard everything below, the sourceMappingURL's actually are there when I examine page source. I was searching the output files but I guess it makes sense that they wouldn't be there since a lot of this is composed on the clientside. Also I think my browser was doing some weird caching because I had to delete the .svelte-kit folder and restart dev for it to show the maps after enabling css.devSourcemap.

The only quirk is that the CSS selectors contain random strings (for making the selector unique to that component I assume) while the map contains the original selector. Its not a huge issue, but is there a way of showing the original selector instead? Maybe this is a just a browser thing. Screenshot_20220508_092715


Edit - disregard this Thanks for the quick reply. I tried this without success for either dev or build. sourceMappingURL isn't appended to css and no .map files appear in the output.

Here's my svelte.config.js ('m just using the base sveltekit demo project, with "@sveltejs/kit": "next" and "svelte": "^3.46.0.

import adapter from '@sveltejs/adapter-auto';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    compilerOptions: {
        enableSourcemap: true
    },
    kit: {
        adapter: adapter(),

        // Override http methods in the Todo forms
        methodOverride: {
            allowed: ['PATCH', 'DELETE']
        },
        vite: {
            css: {
                devSourcemap: true
            }
        }
    }
};

export default config;
jz9423 commented 2 months ago

Has the problem been solved?