Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/getOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ function getOptions(loaderContext) {
options.plugins.push(createWebpackLessPlugin(loaderContext));
}

if (options.sourceMap) {
if (typeof options.sourceMap === 'boolean') {
options.sourceMap = {};
}
if ('outputSourceFiles' in options.sourceMap === false) {
// Include source files as `sourceContents` as sane default since this makes source maps "just work" in most cases
options.sourceMap.outputSourceFiles = true;
}
}

return options;
}

Expand Down
1 change: 1 addition & 0 deletions test/helpers/createSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const lessOptions = {
'--source-map',
`--source-map-basepath=${projectPath}`,
`--source-map-rootpath=${projectPath}`,
'--source-map-less-inline',
],
'import-paths': [
`--include-path=${path.resolve(fixturesPath, 'node_modules')}`,
Expand Down
22 changes: 21 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ test('should transform urls', async () => {
await compileAndCompare('url-path');
});

test('should generate source maps', async () => {
test('should generate source maps with sourcesContent by default', async () => {
let inspect;
const rules = moduleRules.basic({ sourceMap: true }, {}, (i) => {
inspect = i;
Expand All @@ -177,10 +177,30 @@ test('should generate source maps', async () => {
]);
const [actualCss, actualMap] = inspect.arguments;

expect(Array.isArray(actualMap.sourcesContent)).toBe(true);
expect(actualMap.sourcesContent.length).toBe(2);

// We can't actually compare the sourcesContent because it's slightly different because of our import rewriting
delete actualMap.sourcesContent;
delete expectedMap.sourcesContent;

expect(actualCss).toEqual(expectedCss);
expect(actualMap).toEqual(expectedMap);
});

test('should be possible to override sourceMap.outputSourceFiles', async () => {
let inspect;
const rules = moduleRules.basic({ sourceMap: { outputSourceFiles: false } }, {}, (i) => {
inspect = i;
});

await compile('source-map', rules);

const [actualMap] = inspect.arguments;

expect(actualMap).not.toHaveProperty('sourcesContent');
});

test('should install plugins', async () => {
let pluginInstalled = false;
// Using prototype inheritance here since Less plugins are usually instances of classes
Expand Down