developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8.03k stars 362 forks source link

How to disable css soucemap? #944

Closed MinJieLiu closed 2 years ago

MinJieLiu commented 2 years ago

https://github.com/developit/microbundle/blob/master/src/index.js#L489

css should not need sourcemap. It will have warnings on various scaffolding.

image

If it is enabled, it means that I must publish the src directory to npm, otherwise the source information in it cannot be found.

image

https://github.com/MinJieLiu/react-photo-view

rschristian commented 2 years ago

You can disable sourcemaps with the following:

$ microbundle --no-sourcemap

This is listed in the CLI options.

MinJieLiu commented 2 years ago

--no-sourcemap

But this will also close the sourcemap of js 😥.

I just want to disable sourcemap in css.

rschristian commented 2 years ago

Not sure I follow. If your issue is that you don't ship the source so sourcemaps are ineffective, how are the JS sourcemaps of any use?

I think this is best solved by using a simple post-build script:

post-build.mjs

import { promises as fs } from 'node:fs';

let css = await fs.readFile('./dist/index.css', 'utf-8');
css = css.replace(/\r?\n.*/g, '');
await fs.writeFile('./dist/index.css', css);
await fs.rm('./dist/index.css.map');
$ microbundle && node post-build.mjs