diff --git a/fixtures/css/same_filename.css b/fixtures/css/same_filename.css new file mode 100644 index 00000000..78b2927b --- /dev/null +++ b/fixtures/css/same_filename.css @@ -0,0 +1,17 @@ +h4 { + background: top left url('./../images/symfony_logo.png') no-repeat; +} + +h5 { + background: top left url('./../images/same_filename/symfony_logo.png') no-repeat; +} + +@font-face { + font-family: 'Roboto'; + src: url('./../fonts/Roboto.woff2') format('woff2'); +} + +@font-face { + font-family: 'Roboto2'; + src: url('./../fonts/same_filename/Roboto.woff2') format('woff2'); +} \ No newline at end of file diff --git a/fixtures/fonts/same_filename/Roboto.woff2 b/fixtures/fonts/same_filename/Roboto.woff2 new file mode 100644 index 00000000..0707d9ab Binary files /dev/null and b/fixtures/fonts/same_filename/Roboto.woff2 differ diff --git a/fixtures/images/same_filename/symfony_logo.png b/fixtures/images/same_filename/symfony_logo.png new file mode 100644 index 00000000..c065647d Binary files /dev/null and b/fixtures/images/same_filename/symfony_logo.png differ diff --git a/lib/config-generator.js b/lib/config-generator.js index 908b3686..8d55b4c9 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -127,7 +127,7 @@ class ConfigGenerator { test: /\.(png|jpg|jpeg|gif|ico|svg)$/, loader: 'file-loader', options: { - name: `images/[name]${this.webpackConfig.useVersioning ? '.[hash]' : ''}.[ext]`, + name: 'images/[name].[hash:8].[ext]', publicPath: this.webpackConfig.getRealPublicPath() } }, @@ -135,7 +135,7 @@ class ConfigGenerator { test: /\.(woff|woff2|ttf|eot|otf)$/, loader: 'file-loader', options: { - name: `fonts/[name]${this.webpackConfig.useVersioning ? '.[hash]' : ''}.[ext]`, + name: 'fonts/[name].[hash:8].[ext]', publicPath: this.webpackConfig.getRealPublicPath() } }, diff --git a/test/functional.js b/test/functional.js index 5f839206..ed729010 100644 --- a/test/functional.js +++ b/test/functional.js @@ -62,8 +62,8 @@ describe('Functional tests using webpack', function() { 'main.js', 'font.css', 'bg.css', - 'fonts/Roboto.woff2', - 'images/symfony_logo.png', + 'fonts/Roboto.9896f773.woff2', + 'images/symfony_logo.ea1ca6f7.png', 'manifest.json' ]); @@ -87,11 +87,11 @@ describe('Functional tests using webpack', function() { ); webpackAssert.assertManifestPath( 'build/fonts/Roboto.woff2', - '/build/fonts/Roboto.woff2' + '/build/fonts/Roboto.9896f773.woff2' ); webpackAssert.assertManifestPath( 'build/images/symfony_logo.png', - '/build/images/symfony_logo.png' + '/build/images/symfony_logo.ea1ca6f7.png' ); done(); @@ -119,11 +119,11 @@ describe('Functional tests using webpack', function() { webpackAssert.assertOutputFileContains( 'bg.css', - 'http://localhost:8090/assets/images/symfony_logo.png' + 'http://localhost:8090/assets/images/symfony_logo.ea1ca6f7.png' ); webpackAssert.assertOutputFileContains( 'font.css', - 'http://localhost:8090/assets/fonts/Roboto.woff2' + 'http://localhost:8090/assets/fonts/Roboto.9896f773.woff2' ); // manifest file has CDN in value webpackAssert.assertManifestPath( @@ -172,7 +172,7 @@ describe('Functional tests using webpack', function() { webpackAssert.assertOutputFileContains( 'bg.css', - 'http://localhost:8090/assets/images/symfony_logo.png' + 'http://localhost:8090/assets/images/symfony_logo.ea1ca6f7.png' ); // manifest file has CDN in value webpackAssert.assertManifestPath( @@ -285,20 +285,20 @@ describe('Functional tests using webpack', function() { '0.d002be21e9bcf76057e9.js', // chunks are also versioned 'main.292c0347ed1240663cb1.js', 'h1.c84caea6dd12bba7955dee9fedd5fd03.css', - 'bg.42ced8eae2254268bb3c65f1e65bd041.css', + 'bg.483832e48e67e6a3b7f0ae064eadca51.css', 'manifest.json' ] ); expect(path.join(config.outputPath, 'images')).to.be.a.directory() .with.files([ - 'symfony_logo.ea1ca6f7f3719118f301a5cfcb1df3c0.png' + 'symfony_logo.ea1ca6f7.png' ] ); webpackAssert.assertOutputFileContains( - 'bg.42ced8eae2254268bb3c65f1e65bd041.css', - '/build/images/symfony_logo.ea1ca6f7f3719118f301a5cfcb1df3c0.png' + 'bg.483832e48e67e6a3b7f0ae064eadca51.css', + '/build/images/symfony_logo.ea1ca6f7.png' ); done(); @@ -323,28 +323,76 @@ describe('Functional tests using webpack', function() { expect(path.join(config.outputPath, 'images')).to.be.a.directory() .with.files([ - 'symfony_logo.png' + 'symfony_logo.ea1ca6f7.png' ] ); expect(path.join(config.outputPath, 'fonts')).to.be.a.directory() .with.files([ - 'Roboto.woff2' + 'Roboto.9896f773.woff2' ] ); webpackAssert.assertOutputFileContains( 'bg.css', - '/build/images/symfony_logo.png' + '/build/images/symfony_logo.ea1ca6f7.png' ); + webpackAssert.assertOutputFileContains( 'font.css', - '/build/fonts/Roboto.woff2' + '/build/fonts/Roboto.9896f773.woff2' + ); + + done(); + }); + }); + + it('two fonts or images with the same filename should not output a single file', (done) => { + const config = createWebpackConfig('www/build', 'dev'); + config.setPublicPath('/build'); + config.addStyleEntry('styles', './css/same_filename.css'); + config.enableSassLoader(); + + testSetup.runWebpack(config, (webpackAssert) => { + expect(config.outputPath).to.be.a.directory() + .with.files([ + 'styles.css', + 'manifest.json' + ] + ); + + expect(path.join(config.outputPath, 'images')).to.be.a.directory() + .with.files([ + 'symfony_logo.ea1ca6f7.png', + 'symfony_logo.f27119c2.png' + ] + ); + + expect(path.join(config.outputPath, 'fonts')).to.be.a.directory() + .with.files([ + 'Roboto.9896f773.woff2', + 'Roboto.3c37aa69.woff2' + ] ); webpackAssert.assertOutputFileContains( - 'font.css', - '/build/fonts/Roboto.woff2' + 'styles.css', + '/build/images/symfony_logo.ea1ca6f7.png' + ); + + webpackAssert.assertOutputFileContains( + 'styles.css', + '/build/images/symfony_logo.f27119c2.png' + ); + + webpackAssert.assertOutputFileContains( + 'styles.css', + '/build/fonts/Roboto.9896f773.woff2' + ); + + webpackAssert.assertOutputFileContains( + 'styles.css', + '/build/fonts/Roboto.3c37aa69.woff2' ); done(); @@ -687,7 +735,7 @@ module.exports = { expect(config.outputPath).to.be.a.directory().with.deep.files([ 'main.js', 'main.css', - 'images/logo.png', + 'images/logo.82b9c7a5.png', 'manifest.json' ]);