Skip to content

Commit

Permalink
fix: [scss] remove sourceMappingURL from result.code (#297)
Browse files Browse the repository at this point in the history
* sass: remove sourceMappingURL from result.code

* Add test for scss srcMap

Co-authored-by: Christian Kaisermann <christian@kaisermann.me>
  • Loading branch information
milahu and kaisermann committed Jan 29, 2021
1 parent f58c6cd commit 2ff48f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/transformers/scss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const tildeImporter: Importer = (url, prev) => {

const modulePath = join('node_modules', ...url.slice(1).split(/[\\/]/g));

// todo: maybe create a smaller findup utility method?
const foundPath = findUp({ what: modulePath, from: prev });

// istanbul ignore if
Expand Down Expand Up @@ -68,6 +67,7 @@ const transformer: Transformer<Options.Sass> = async ({
...options,
includePaths: getIncludePaths(filename, options.includePaths),
outFile: `${filename}.css`,
omitSourceMapUrl: true, // return sourcemap only in result.map
};

const sassOptions = {
Expand Down
14 changes: 14 additions & 0 deletions test/transformers/scss.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { resolve } from 'path';
import sveltePreprocess from '../../src';
import { preprocess } from '../utils';
import type { Options } from '../../src/types';
import { transformer } from '../../src/transformers/scss';

const implementation: Options.Sass['implementation'] = {
render(options, callback) {
Expand Down Expand Up @@ -121,4 +122,17 @@ describe('transformer - scss', () => {
}</style>"
`);
});

it('returns the source map and removes sourceMappingURL from code', async () => {
const content = 'div{color:red}';
const filename = '/file';
const options = {
sourceMap: true,
};

const { map, code } = await transformer({ content, filename, options });

expect(code).not.toContain('sourceMappingURL');
expect(map).toBeTruthy();
});
});

0 comments on commit 2ff48f8

Please sign in to comment.