Skip to content

Commit

Permalink
Merge pull request #186 from webpack-contrib/fix/sources-content-missing
Browse files Browse the repository at this point in the history
fix: sourcesContent missing in source maps
  • Loading branch information
jhnns authored Mar 30, 2017
2 parents 786aa59 + df28035 commit 7a985cd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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

0 comments on commit 7a985cd

Please sign in to comment.