Skip to content

Commit 5091168

Browse files
committed
bug #697 Fix source maps being generated by default in dev (Lyrkan)
This PR was merged into the master branch. Discussion ---------- Fix source maps being generated by default in dev When `config.devtool` is not set (which is the current behavior with `enableSourceMaps(false)` or when the function is not called at all) the `eval` source maps type is used in development mode. This PR sets the default value to `false` to make sure that no source map is being generated in those cases (fixes #695). Commits ------- ab8ac7c Fix source maps being generated by default in dev
2 parents a4ae7ce + ab8ac7c commit 5091168

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

lib/config-generator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class ConfigGenerator {
7070
},
7171
plugins: this.buildPluginsConfig(),
7272
optimization: this.buildOptimizationConfig(),
73-
watchOptions: this.buildWatchOptionsConfig()
73+
watchOptions: this.buildWatchOptionsConfig(),
74+
devtool: false,
7475
};
7576

7677
if (this.webpackConfig.useSourceMaps) {

test/config-generator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ describe('The config-generator function', () => {
125125
config.useSourceMaps = false;
126126

127127
const actualConfig = configGenerator(config);
128-
expect(actualConfig.devtool).to.be.undefined;
128+
expect(actualConfig.devtool).to.be.false;
129129

130130
expect(JSON.stringify(actualConfig.module.rules)).to.not.contain('?sourceMap');
131131
});

test/functional.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -659,10 +659,9 @@ describe('Functional tests using webpack', function() {
659659
webpackAssert.assertOutputFileDoesNotHaveSourcemap(
660660
'main.js'
661661
);
662-
// TODO - fix this, there IS always a sourcemap in .sass files
663-
// webpackAssert.assertOutputFileDoesNotHaveSourcemap(
664-
// 'bg.css'
665-
// );
662+
webpackAssert.assertOutputFileDoesNotHaveSourcemap(
663+
'bg.css'
664+
);
666665
webpackAssert.assertOutputFileDoesNotHaveSourcemap(
667666
'font.css'
668667
);
@@ -2586,10 +2585,10 @@ module.exports = {
25862585
const integrityData = getIntegrityData(config);
25872586
const expectedHashes = {
25882587
'/build/runtime.js': 'sha384-GhoJXFTd5hHxARTOCT3RTrcOdggU7hmL/esw02KNiVIWsdumxg20TRjgdzXBMGfE',
2589-
'/build/main.js': 'sha384-ymG7OyjISWrOpH9jsGvajKMDEOP/mKJq8bHC0XdjQA6P8sg2nu+2RLQxcNNwE/3J',
2590-
'/build/main~other.js': 'sha384-4g+Zv0iELStVvA4/B27g4TQHUMwZttA5TEojjUyB8Gl5p7sarU4y+VTSGMrNab8n',
2588+
'/build/main.js': 'sha384-TnYCkFJqLSzDkhJOQRhe1JPC6MhfAurWWjEqNVNa0YK8N4a89mMsaAHFOP+8u3Oq',
2589+
'/build/main~other.js': 'sha384-XFgE9lNhD68TAYS7RjTCP7aXyjUxWftiNFMNxG7izJZ3urzp/7u1Tn4DMARxCLIw',
25912590
'/build/main~other.css': 'sha384-hfZmq9+2oI5Cst4/F4YyS2tJAAYdGz7vqSMP8cJoa8bVOr2kxNRLxSw6P8UZjwUn',
2592-
'/build/other.js': 'sha384-ZU3hiTN/+Va9WVImPi+cI0/j/Q7SzAVezqL1aEXha8sVgE5HU6/0wKUxj1LEnkC9',
2591+
'/build/other.js': 'sha384-xZXDGUPL+RIK36nvmtEbJleQy9BCgG89MXkrYTNcbpDcZs4C1VbWAFMFehc8Mmnw',
25932592

25942593
// vendors~main~other.js's hash is not tested since its
25952594
// content seems to change based on the build environment.
@@ -2619,10 +2618,10 @@ module.exports = {
26192618
const integrityData = getIntegrityData(config);
26202619
const expectedHashes = {
26212620
'http://localhost:8090/assets/runtime.js': 'sha256-qW5QarAS9yWb4YTF5gVKNF24g4p5GayDErYme10iu7A=',
2622-
'http://localhost:8090/assets/main.js': 'sha256-RtW3TYA1SBHUGuBnIBBJZ7etIGyYisjargouvET4sFE=',
2623-
'http://localhost:8090/assets/main~other.js': 'sha256-q9xPQWa0UBbMPUNmhDaDuBFjV2gZU6ICiKzLN7jPccc=',
2621+
'http://localhost:8090/assets/main.js': 'sha256-GCcvESjPed0klG3VxS0DLeRZ0UNJl/Ln210ldsAz9U4=',
2622+
'http://localhost:8090/assets/main~other.js': 'sha256-iNXyEC346lU4Z8e4pxtatvElwLSJu/in5Mpg+EsIrwA=',
26242623
'http://localhost:8090/assets/main~other.css': 'sha256-KVo9sI0v6MnbxPg/xZMSn2XE7qIChWiDh1uED1tP5Fo=',
2625-
'http://localhost:8090/assets/other.js': 'sha256-rxT6mp9VrLO1++6G3g/VSLGisznX838ALokQhD3Jmyc=',
2624+
'http://localhost:8090/assets/other.js': 'sha256-O2agOBc6WzelNGpE0dg3k6X1jtEVTRq9ogik4UAlBjg=',
26262625

26272626
// vendors~main~other.js's hash is not tested since its
26282627
// content seems to change based on the build environment.
@@ -2651,10 +2650,10 @@ module.exports = {
26512650
const integrityData = getIntegrityData(config);
26522651
const expectedHashes = {
26532652
'/build/runtime.js': 'sha256-wxWX1GOm4edacCjvQsqZ1hG9tls4ZtuUOGQ8goGNg54= sha512-eiQrrAyaBpUlypIGVURWONjsAW8sImJllkwQ6NSDK6tIVNy/lInthruFT30x/OGRfHa4aYEaOHriEjisoxcw1Q==',
2654-
'/build/main.js': 'sha256-RtW3TYA1SBHUGuBnIBBJZ7etIGyYisjargouvET4sFE= sha512-/wl1U/L6meBga5eeRTxPz5BxFiLmwL/kjy1NTcK0DNdxV3oUI/zZ9DEDU43Cl7XqGMnUH8pJhhFJR+1k9vZrYQ==',
2655-
'/build/main~other.js': 'sha256-q9xPQWa0UBbMPUNmhDaDuBFjV2gZU6ICiKzLN7jPccc= sha512-1xuC/Y+goI01JUPVYBQOpPY36ttTXnZFOBsTgNPCJu53b2/ccFqzeW3abV3KG5mFzo4cfSUOS7AXjj8ajp/MjA==',
2653+
'/build/main.js': 'sha256-GCcvESjPed0klG3VxS0DLeRZ0UNJl/Ln210ldsAz9U4= sha512-dxwgdqyuVFpEn4D/xSTLDf524+OSdwBgAYwB6zRswaM4SszrrClIBK3FScktIU3CNWEqiHgjHPj2SnQTLAonGg==',
2654+
'/build/main~other.js': 'sha256-iNXyEC346lU4Z8e4pxtatvElwLSJu/in5Mpg+EsIrwA= sha512-ay9A5f9PnQgqkt0obZY0UD+Bx0IVf13NijC74/Gek6Fl5JoOpHMXBlqWxZnMlnbP0/OCm1lgKRDitLd4vys87w==',
26562655
'/build/main~other.css': 'sha256-6AltZJTjdVuLywCBE8qQevkscxazmWyh/19OL6cxkwY= sha512-zE1kAcqJ/jNnycEwELK7BfauEgRlK6cGrN+9urz4JI1K+s5BpglYFF9G0VOiSA7Kj3w46XX1WcjZ5w5QohBFEw==',
2657-
'/build/other.js': 'sha256-rxT6mp9VrLO1++6G3g/VSLGisznX838ALokQhD3Jmyc= sha512-XZjuolIG3/QW1PwAIaPCtQZvKvkPNsAsoUjQdDqlW/uStd9lBrT3w16WrBdc3qe4X11bGkyA7IQpQwN3FGkPMA==',
2656+
'/build/other.js': 'sha256-O2agOBc6WzelNGpE0dg3k6X1jtEVTRq9ogik4UAlBjg= sha512-tXToyMmW0EuKUF667SlO7QJZFg8eE6fHSmZIk7G0qIo9oUhgMQzwWyc5UpzlHlTOoLaKWB+UNgjOb0x3t28PZg==',
26582657

26592658
// vendors~main~other.js's hash is not tested since its
26602659
// content seems to change based on the build environment.

test/helpers/assert.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,29 @@ class Assert {
7575
assertOutputFileHasSourcemap(filePath) {
7676
const actualContents = readOutputFile(this.webpackConfig, filePath);
7777

78-
if (!actualContents.includes('sourceMappingURL')) {
78+
const hasSourceMappingUrl = actualContents.includes('sourceMappingURL');
79+
const hasSourceUrl = actualContents.includes('sourceURL');
80+
81+
if (!hasSourceMappingUrl && !hasSourceUrl) {
7982
throw new Error(`No sourcemap found for ${filePath}!`);
8083
}
8184

82-
const sourceMappingUrlContents = actualContents.split('sourceMappingURL')[1];
85+
if (hasSourceMappingUrl) {
86+
const sourceMappingUrlContents = actualContents.split('sourceMappingURL')[1];
8387

84-
// if you set config.devtool = '#inline-source-map', but then
85-
// incorrectly configure css/sass sourcemaps, you WILL have
86-
// a sourcemap, but it will be too small / i.e. basically empty
87-
if (sourceMappingUrlContents.length < 200) {
88-
throw new Error(`Sourcemap for ${filePath} appears to be empty!`);
88+
// if you set config.devtool = '#inline-source-map', but then
89+
// incorrectly configure css/sass sourcemaps, you WILL have
90+
// a sourcemap, but it will be too small / i.e. basically empty
91+
if (sourceMappingUrlContents.length < 200) {
92+
throw new Error(`Sourcemap for ${filePath} appears to be empty!`);
93+
}
8994
}
9095
}
9196

9297
assertOutputFileDoesNotHaveSourcemap(filePath) {
9398
const actualContents = readOutputFile(this.webpackConfig, filePath);
9499

95-
if (actualContents.includes('sourceMappingURL')) {
100+
if (actualContents.includes('sourceMappingURL') || actualContents.includes('sourceURL')) {
96101
throw new Error(`Sourcemap found for ${filePath}!`);
97102
}
98103
}

0 commit comments

Comments
 (0)