Skip to content

Commit 776be52

Browse files
authored
bug #161 Fix JS query string versioning when using addStyleEntry (Lyrkan)
2 parents db050c2 + b3befcc commit 776be52

File tree

2 files changed

+86
-24
lines changed

2 files changed

+86
-24
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
'use strict';
1111

12-
const path = require('path');
13-
1412
function DeleteUnusedEntriesJSPlugin(entriesToDelete = []) {
1513
this.entriesToDelete = entriesToDelete;
1614
}
@@ -25,7 +23,7 @@ DeleteUnusedEntriesJSPlugin.prototype.apply = function(compiler) {
2523

2624
// loop over the output files and find the 1 that ends in .js
2725
chunk.files.forEach((filename) => {
28-
if (path.extname(filename) === '.js') {
26+
if (/\.js(\?[^.]*)?$/.test(filename)) {
2927
fileDeleteCount++;
3028
// remove the output file
3129
delete compilation.assets[filename];

test/functional.js

Lines changed: 85 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -243,30 +243,94 @@ describe('Functional tests using webpack', function() {
243243
});
244244
});
245245

246-
it('addStyleEntry .js files are removed', (done) => {
247-
const config = createWebpackConfig('web', 'dev');
248-
config.addEntry('main', './js/no_require');
249-
config.setPublicPath('/');
250-
config.addStyleEntry('styles', './css/h1_style.css');
246+
describe('addStyleEntry .js files are removed', () => {
247+
it('Without versioning', (done) => {
248+
const config = createWebpackConfig('web', 'dev');
249+
config.addEntry('main', './js/no_require');
250+
config.setPublicPath('/');
251+
config.addStyleEntry('styles', './css/h1_style.css');
251252

252-
testSetup.runWebpack(config, (webpackAssert) => {
253-
expect(config.outputPath).to.be.a.directory()
254-
// public.js should not exist
255-
.with.files(['main.js', 'styles.css', 'manifest.json']);
253+
testSetup.runWebpack(config, (webpackAssert) => {
254+
expect(config.outputPath).to.be.a.directory()
255+
// public.js should not exist
256+
.with.files(['main.js', 'styles.css', 'manifest.json']);
256257

257-
webpackAssert.assertOutputFileContains(
258-
'styles.css',
259-
'font-size: 50px;'
260-
);
261-
webpackAssert.assertManifestPathDoesNotExist(
262-
'styles.js'
263-
);
264-
webpackAssert.assertManifestPath(
265-
'styles.css',
266-
'/styles.css'
267-
);
258+
webpackAssert.assertOutputFileContains(
259+
'styles.css',
260+
'font-size: 50px;'
261+
);
262+
webpackAssert.assertManifestPathDoesNotExist(
263+
'styles.js'
264+
);
265+
webpackAssert.assertManifestPath(
266+
'styles.css',
267+
'/styles.css'
268+
);
268269

269-
done();
270+
done();
271+
});
272+
});
273+
274+
it('With default versioning', (done) => {
275+
const config = createWebpackConfig('web', 'dev');
276+
config.addEntry('main', './js/no_require');
277+
config.setPublicPath('/');
278+
config.addStyleEntry('styles', './css/h1_style.css');
279+
config.enableVersioning(true);
280+
281+
testSetup.runWebpack(config, (webpackAssert) => {
282+
expect(config.outputPath).to.be.a.directory()
283+
.with.files([
284+
'main.f1e0a9350e13fe3a597e.js',
285+
'styles.c84caea6dd12bba7955dee9fedd5fd03.css',
286+
'manifest.json'
287+
]);
288+
289+
webpackAssert.assertOutputFileContains(
290+
'styles.c84caea6dd12bba7955dee9fedd5fd03.css',
291+
'font-size: 50px;'
292+
);
293+
webpackAssert.assertManifestPathDoesNotExist(
294+
'styles.js'
295+
);
296+
webpackAssert.assertManifestPath(
297+
'styles.css',
298+
'/styles.c84caea6dd12bba7955dee9fedd5fd03.css'
299+
);
300+
301+
done();
302+
});
303+
});
304+
305+
it('With query string versioning', (done) => {
306+
const config = createWebpackConfig('web', 'dev');
307+
config.addEntry('main', './js/no_require');
308+
config.setPublicPath('/');
309+
config.addStyleEntry('styles', './css/h1_style.css');
310+
config.enableVersioning(true);
311+
config.configureFilenames({
312+
js: '[name].js?[chunkhash:16]',
313+
css: '[name].css?[contenthash:16]'
314+
});
315+
316+
testSetup.runWebpack(config, (webpackAssert) => {
317+
expect(config.outputPath).to.be.a.directory()
318+
.with.files(['main.js', 'styles.css', 'manifest.json']);
319+
320+
webpackAssert.assertOutputFileContains(
321+
'styles.css',
322+
'font-size: 50px;'
323+
);
324+
webpackAssert.assertManifestPathDoesNotExist(
325+
'styles.js'
326+
);
327+
webpackAssert.assertManifestPath(
328+
'styles.css',
329+
'/styles.css?c84caea6dd12bba7'
330+
);
331+
332+
done();
333+
});
270334
});
271335
});
272336

0 commit comments

Comments
 (0)