{"id":22630,"library":"vite-plugin-css-sourcemap","title":"Vite Plugin CSS Sourcemap","description":"A Vite plugin (v1.0.5) that generates CSS sourcemaps during production builds. Unlike Vite's built-in CSS sourcemap support, this plugin provides fine-grained control over sourcemap output location and URL generation, supporting custom extensions like .scss and .less. It hooks into Vite's build pipeline via the `vite:css-post` plugin to emit sourcemap files and add references to CSS output. Requires Vite >=5.0.0 and peer dependencies for Sass processing. Compatible with Vite 5.x and 6.x. Released under MIT license.","status":"active","version":"1.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/MarioCadenas/vite-plugin-css-sourcemap","tags":["javascript","vite","rollup","vite-plugin","css","sourcemap","typescript"],"install":[{"cmd":"npm install vite-plugin-css-sourcemap","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-css-sourcemap","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-css-sourcemap","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core build tool, required as peer dependency.","package":"vite","optional":false},{"reason":"Required for .scss file processing; can be replaced with sass-embedded.","package":"sass","optional":true},{"reason":"Alternative Sass engine for .scss files.","package":"sass-embedded","optional":true}],"imports":[{"note":"The plugin is exported as a default export. Named import will fail.","wrong":"import { cssSourcemap } from 'vite-plugin-css-sourcemap'","symbol":"default","correct":"import cssSourcemap from 'vite-plugin-css-sourcemap'"},{"note":"In CommonJS, the default export is under .default. Direct require() gives an object, not the function.","wrong":"const cssSourcemap = require('vite-plugin-css-sourcemap')","symbol":"CjsRequire","correct":"const cssSourcemap = require('vite-plugin-css-sourcemap').default"},{"note":"Vite plugins have their own Plugin type; the package does not export a custom type.","wrong":"import { Plugin } from 'vite-plugin-css-sourcemap'","symbol":"Plugin type","correct":"import type { Plugin } from 'vite'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nimport cssSourcemap from 'vite-plugin-css-sourcemap';\n\nexport default defineConfig({\n  plugins: [cssSourcemap()],\n  build: {\n    cssCodeSplit: true,\n    sourcemap: true,\n  },\n});\n\n// Ensure at least one CSS file is imported in your project\n// Run 'vite build' to produce CSS with sourcemap references","lang":"typescript","description":"Basic setup with Vite config including the plugin and enabling build sourcemaps."},"warnings":[{"fix":"Use only for production builds with 'vite build'.","message":"Plugin only works during build; no effect in dev mode.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Add 'build.sourcemap: true' to vite.config.","message":"Must set 'build.sourcemap' to true or 'hidden' in Vite config for sourcemaps to be generated.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install sass or sass-embedded.","message":"For .scss files, either 'sass' or 'sass-embedded' must be installed as a dev dependency.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update to v1.0.1 or later.","message":"In v1.0.0, entry with no hash could produce null sourcemap; fixed in v1.0.1.","severity":"breaking","affected_versions":"<=1.0.0"},{"fix":"Update to v1.0.2 or later.","message":"In v1.0.2, path argument must be a string; earlier versions crashed on non-string paths.","severity":"breaking","affected_versions":"<=1.0.1"},{"fix":"Use 'enabled: true' instead of 'enable: true'.","message":"The 'enable' option is deprecated; use 'enabled' instead (typo fix).","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use the plugin only in production builds via 'vite build'.","cause":"Plugin is designed only for build phase.","error":"Error: The plugin is not working in dev mode"},{"fix":"Install sass or sass-embedded: 'npm install sass --save-dev'","cause":"Missing peer dependency for scss processing.","error":"Error: Cannot find module 'sass'"},{"fix":"Use default import: 'import cssSourcemap from 'vite-plugin-css-sourcemap'' or in CJS: 'const cssSourcemap = require('vite-plugin-css-sourcemap').default'.","cause":"Incorrect import or require pattern.","error":"TypeError: cssSourcemap is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}