Skip to content

Commit 929a253

Browse files
authored
bug #170 Fix temporary map files not being deleted in production mode (Lyrkan)
2 parents 568fb98 + 1d2b1a6 commit 929a253

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

lib/webpack/delete-unused-entries-js-plugin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ DeleteUnusedEntriesJSPlugin.prototype.apply = function(compiler) {
2323

2424
// loop over the output files and find the 1 that ends in .js
2525
chunk.files.forEach((filename) => {
26-
if (/\.js(\?[^.]*)?$/.test(filename)) {
26+
if (/\.js(\.map)?(\?[^.]*)?$/.test(filename)) {
2727
fileDeleteCount++;
2828
// remove the output file
2929
delete compilation.assets[filename];
@@ -32,10 +32,10 @@ DeleteUnusedEntriesJSPlugin.prototype.apply = function(compiler) {
3232
}
3333
});
3434

35-
// sanity check: make sure 1 file was deleted
36-
// if there's some edge case where multiple .js files
35+
// sanity check: make sure 1 or 2 files were deleted
36+
// if there's some edge case where more .js files
3737
// or 0 .js files might be deleted, I'd rather error
38-
if (fileDeleteCount !== 1) {
38+
if (fileDeleteCount === 0 || fileDeleteCount > 2) {
3939
throw new Error(`Problem deleting JS entry for ${chunk.name}: ${fileDeleteCount} files were deleted`);
4040
}
4141
}

test/functional.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,37 @@ describe('Functional tests using webpack', function() {
332332
done();
333333
});
334334
});
335+
336+
it('With source maps in production mode', (done) => {
337+
const config = createWebpackConfig('web', 'production');
338+
config.addEntry('main', './js/no_require');
339+
config.setPublicPath('/');
340+
config.addStyleEntry('styles', './css/h1_style.css');
341+
config.enableSourceMaps(true);
342+
343+
testSetup.runWebpack(config, (webpackAssert) => {
344+
expect(config.outputPath).to.be.a.directory()
345+
.with.files([
346+
'main.js',
347+
'main.js.map',
348+
'styles.css',
349+
'styles.css.map',
350+
'manifest.json'
351+
// no styles.js
352+
// no styles.js.map
353+
]);
354+
355+
webpackAssert.assertManifestPathDoesNotExist(
356+
'styles.js'
357+
);
358+
359+
webpackAssert.assertManifestPathDoesNotExist(
360+
'styles.js.map'
361+
);
362+
363+
done();
364+
});
365+
});
335366
});
336367

337368
it('enableVersioning applies to js, css & manifest', (done) => {

0 commit comments

Comments
 (0)