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

Accept an input source-map, for generating the final source-map #219

Closed
binyamin opened this issue Jun 30, 2022 · 5 comments
Closed

Accept an input source-map, for generating the final source-map #219

binyamin opened this issue Jun 30, 2022 · 5 comments

Comments

@binyamin
Copy link

When a stylesheet has a source-map from a previous transformation, use it to generate the new source-map.

Use-case: A user might transform .scss files into CSS, and then minify it with parcel-css.

@devongovett
Copy link
Member

Parcel already does this. I assume you mean when using the Parcel CSS CLI?

@binyamin
Copy link
Author

binyamin commented Jul 3, 2022

@devongovett Nope. I'm using @parcel/css-wasm, in Deno. Either way, I looked through the Readme and the type definitions. I couldn't find any options which accepted a source-map.

@devongovett
Copy link
Member

devongovett commented Jul 3, 2022

We could support data urls in a sourceMappingURL comment, but referencing files on the filesystem or external URLs won't be supported because Parcel CSS doesn't do any filesystem operations (in WASM there is no access anyway).

I suppose we could also support a separate input string for the source map, but handling that is already possible using Parcel's source map library. Something like this:

const {transform} = require('@parcel/css');
const SourceMap = require('@parcel/source-map');

let result = transform({ /* ... */ });

let prevMap = new SourceMap(PROJECT_ROOT_DIR);
prevMap.addVLQMap(previousSourceMapJSON)

let map = new SourceMap(PROJECT_ROOT_DIR);
map.addVLQMap(JSON.parse(result.map.toString()));
map.extends(prevMap);

@binyamin
Copy link
Author

binyamin commented Jul 3, 2022

@devongovett Thank you. By the way, what does the PROJECT_ROOT_DIR variable do here? Just wondering.

@devongovett
Copy link
Member

All file paths in the source map are stored relative to the project root directory. Typically it'll be the root of your git repository, for example.

Btw, I'm working on support for data urls in sourceMappingURL comments. Will open a PR here once parcel-bundler/source-map#109 is merged.

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

2 participants