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

Files without css not included in sourcemaps #138

Open
IkorJefocur opened this issue Jun 12, 2020 · 0 comments
Open

Files without css not included in sourcemaps #138

IkorJefocur opened this issue Jun 12, 2020 · 0 comments

Comments

@IkorJefocur
Copy link

IkorJefocur commented Jun 12, 2020

I writed simple plugin for gulp, which parses every file to do something with, then stringifies it back. The problem is that when the plugin comes across an empty css source in sourcemap, it does not write it to new sourcemap.

For example, i have 3 files: main.css, addon.css, empty.css. And the last one empty. I also concats all files in one style.css file before pass through my plugin. Here's some code from my plugin:

return through.obj(function(file, enc, next) {
	if (file.isNull()) {
		next(null, file);
		return;
	}

	const ast = css.parse(file.contents + '', {source: file.relative});

	// Here's some plugin logic
	// If I remove this part, nothing will change
	ast.stylesheet.rules = main(ast.stylesheet.rules);
	
	const result = css.stringify(ast, {sourcemap: !!file.sourceMap});
	file.contents = new Buffer(result.code);

	if (file.sourceMap) {
		result.map.file = file.relative;
		applySourceMap(file, result.map);
	}

	this.push(file);
	next();
});

In the output sourcemap empty.css just doesn't exists. And maybe it's ok, because i don't really need empty files in sourcemap, but parser do the same with files, that just don't have css code. I using sass, and have files that only contains mixins, functions, etc.. For example:

// --- some-mixin.sass ---

@mixin some-mixin($param)
	// Mixin contents

So i have sources in sourcemap like [main.sass, <here's must be some-mixnin.sass, but it's doesn't>, addon.sass]. Another problem is, when i use another plugin after mine, for example clean-css, i've got something like this: [main.sass, style.css, addon.sass], where style.css is my output file (and sourcesContents for style.css is null).

Tell me if i do something wrong. But i think it's just bug in parser.

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