From 1c789fb2383d8c23e02ce103c75905833249edd2 Mon Sep 17 00:00:00 2001 From: Rasmus Melchior Jacobsen Date: Thu, 25 Apr 2019 15:47:28 +0200 Subject: [PATCH 1/4] fix(loader): fix publicPath regression ... when the publicPath is set to an empty string. The publicPath should resolve to an empty string in this case and _not_ `/` --- src/loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loader.js b/src/loader.js index 04181c42..a91dd787 100644 --- a/src/loader.js +++ b/src/loader.js @@ -68,7 +68,7 @@ export function pitch(request) { const childFilename = '*'; // eslint-disable-line no-path-concat const publicPath = typeof options.publicPath === 'string' - ? options.publicPath.endsWith('/') + ? options.publicPath === '' || options.publicPath.endsWith('/') ? options.publicPath : `${options.publicPath}/` : typeof options.publicPath === 'function' From 0b4c737caa73a1a5924336c421f935a7748a6d1c Mon Sep 17 00:00:00 2001 From: Rasmus Melchior Jacobsen Date: Fri, 26 Apr 2019 20:37:28 +0200 Subject: [PATCH 2/4] test(loader): Add test for the case when publicPath is an empty string --- .../publicpath-emptystring/expected/main.css | 2 + test/cases/publicpath-emptystring/index.js | 1 + test/cases/publicpath-emptystring/react.svg | 1 + test/cases/publicpath-emptystring/style.css | 1 + .../publicpath-emptystring/webpack.config.js | 37 +++++++++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 test/cases/publicpath-emptystring/expected/main.css create mode 100644 test/cases/publicpath-emptystring/index.js create mode 100644 test/cases/publicpath-emptystring/react.svg create mode 100644 test/cases/publicpath-emptystring/style.css create mode 100644 test/cases/publicpath-emptystring/webpack.config.js diff --git a/test/cases/publicpath-emptystring/expected/main.css b/test/cases/publicpath-emptystring/expected/main.css new file mode 100644 index 00000000..f6674281 --- /dev/null +++ b/test/cases/publicpath-emptystring/expected/main.css @@ -0,0 +1,2 @@ +body { background: red; background-image: url(cd0bb358c45b584743d8ce4991777c42.svg); } + diff --git a/test/cases/publicpath-emptystring/index.js b/test/cases/publicpath-emptystring/index.js new file mode 100644 index 00000000..aa3357bf --- /dev/null +++ b/test/cases/publicpath-emptystring/index.js @@ -0,0 +1 @@ +import './style.css'; diff --git a/test/cases/publicpath-emptystring/react.svg b/test/cases/publicpath-emptystring/react.svg new file mode 100644 index 00000000..5b3b22a4 --- /dev/null +++ b/test/cases/publicpath-emptystring/react.svg @@ -0,0 +1 @@ +logo-on-dark-bg \ No newline at end of file diff --git a/test/cases/publicpath-emptystring/style.css b/test/cases/publicpath-emptystring/style.css new file mode 100644 index 00000000..edcbc24a --- /dev/null +++ b/test/cases/publicpath-emptystring/style.css @@ -0,0 +1 @@ +body { background: red; background-image: url(./react.svg); } diff --git a/test/cases/publicpath-emptystring/webpack.config.js b/test/cases/publicpath-emptystring/webpack.config.js new file mode 100644 index 00000000..eb6125c8 --- /dev/null +++ b/test/cases/publicpath-emptystring/webpack.config.js @@ -0,0 +1,37 @@ +import Self from '../../../src'; + +module.exports = { + entry: './index.js', + module: { + rules: [ + { + test: /\.css$/, + use: [ + { + loader: Self.loader, + options: { + publicPath: '', + }, + }, + 'css-loader', + ], + }, + { + test: /\.(svg|png)$/, + use: [ + { + loader: 'file-loader', + options: { + filename: '[name].[ext]', + }, + }, + ], + }, + ], + }, + plugins: [ + new Self({ + filename: '[name].css', + }), + ], +}; From 8ae0739ee2b1e85d2dffdf7ca67567e183df6f16 Mon Sep 17 00:00:00 2001 From: Rasmus Melchior Jacobsen Date: Fri, 26 Apr 2019 20:45:25 +0200 Subject: [PATCH 3/4] Revert "test(loader): Add test for the case when publicPath is an empty string" This reverts commit d9609af55bc320483bf2b87ad831e95db6cba5d5. --- .../publicpath-emptystring/expected/main.css | 2 - test/cases/publicpath-emptystring/index.js | 1 - test/cases/publicpath-emptystring/react.svg | 1 - test/cases/publicpath-emptystring/style.css | 1 - .../publicpath-emptystring/webpack.config.js | 37 ------------------- 5 files changed, 42 deletions(-) delete mode 100644 test/cases/publicpath-emptystring/expected/main.css delete mode 100644 test/cases/publicpath-emptystring/index.js delete mode 100644 test/cases/publicpath-emptystring/react.svg delete mode 100644 test/cases/publicpath-emptystring/style.css delete mode 100644 test/cases/publicpath-emptystring/webpack.config.js diff --git a/test/cases/publicpath-emptystring/expected/main.css b/test/cases/publicpath-emptystring/expected/main.css deleted file mode 100644 index f6674281..00000000 --- a/test/cases/publicpath-emptystring/expected/main.css +++ /dev/null @@ -1,2 +0,0 @@ -body { background: red; background-image: url(cd0bb358c45b584743d8ce4991777c42.svg); } - diff --git a/test/cases/publicpath-emptystring/index.js b/test/cases/publicpath-emptystring/index.js deleted file mode 100644 index aa3357bf..00000000 --- a/test/cases/publicpath-emptystring/index.js +++ /dev/null @@ -1 +0,0 @@ -import './style.css'; diff --git a/test/cases/publicpath-emptystring/react.svg b/test/cases/publicpath-emptystring/react.svg deleted file mode 100644 index 5b3b22a4..00000000 --- a/test/cases/publicpath-emptystring/react.svg +++ /dev/null @@ -1 +0,0 @@ -logo-on-dark-bg \ No newline at end of file diff --git a/test/cases/publicpath-emptystring/style.css b/test/cases/publicpath-emptystring/style.css deleted file mode 100644 index edcbc24a..00000000 --- a/test/cases/publicpath-emptystring/style.css +++ /dev/null @@ -1 +0,0 @@ -body { background: red; background-image: url(./react.svg); } diff --git a/test/cases/publicpath-emptystring/webpack.config.js b/test/cases/publicpath-emptystring/webpack.config.js deleted file mode 100644 index eb6125c8..00000000 --- a/test/cases/publicpath-emptystring/webpack.config.js +++ /dev/null @@ -1,37 +0,0 @@ -import Self from '../../../src'; - -module.exports = { - entry: './index.js', - module: { - rules: [ - { - test: /\.css$/, - use: [ - { - loader: Self.loader, - options: { - publicPath: '', - }, - }, - 'css-loader', - ], - }, - { - test: /\.(svg|png)$/, - use: [ - { - loader: 'file-loader', - options: { - filename: '[name].[ext]', - }, - }, - ], - }, - ], - }, - plugins: [ - new Self({ - filename: '[name].css', - }), - ], -}; From 85643bb865c238708d4b585673f8b0a31ee44c5f Mon Sep 17 00:00:00 2001 From: Rasmus Melchior Jacobsen Date: Fri, 26 Apr 2019 20:51:17 +0200 Subject: [PATCH 4/4] test(loader): Add test for the case when publicPath is an empty string --- .../publicpath-emptystring/expected/main.css | 2 + test/cases/publicpath-emptystring/index.js | 1 + test/cases/publicpath-emptystring/react.svg | 1 + test/cases/publicpath-emptystring/style.css | 1 + .../publicpath-emptystring/webpack.config.js | 37 +++++++++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 test/cases/publicpath-emptystring/expected/main.css create mode 100644 test/cases/publicpath-emptystring/index.js create mode 100644 test/cases/publicpath-emptystring/react.svg create mode 100644 test/cases/publicpath-emptystring/style.css create mode 100644 test/cases/publicpath-emptystring/webpack.config.js diff --git a/test/cases/publicpath-emptystring/expected/main.css b/test/cases/publicpath-emptystring/expected/main.css new file mode 100644 index 00000000..f6674281 --- /dev/null +++ b/test/cases/publicpath-emptystring/expected/main.css @@ -0,0 +1,2 @@ +body { background: red; background-image: url(cd0bb358c45b584743d8ce4991777c42.svg); } + diff --git a/test/cases/publicpath-emptystring/index.js b/test/cases/publicpath-emptystring/index.js new file mode 100644 index 00000000..aa3357bf --- /dev/null +++ b/test/cases/publicpath-emptystring/index.js @@ -0,0 +1 @@ +import './style.css'; diff --git a/test/cases/publicpath-emptystring/react.svg b/test/cases/publicpath-emptystring/react.svg new file mode 100644 index 00000000..5b3b22a4 --- /dev/null +++ b/test/cases/publicpath-emptystring/react.svg @@ -0,0 +1 @@ +logo-on-dark-bg \ No newline at end of file diff --git a/test/cases/publicpath-emptystring/style.css b/test/cases/publicpath-emptystring/style.css new file mode 100644 index 00000000..edcbc24a --- /dev/null +++ b/test/cases/publicpath-emptystring/style.css @@ -0,0 +1 @@ +body { background: red; background-image: url(./react.svg); } diff --git a/test/cases/publicpath-emptystring/webpack.config.js b/test/cases/publicpath-emptystring/webpack.config.js new file mode 100644 index 00000000..eb6125c8 --- /dev/null +++ b/test/cases/publicpath-emptystring/webpack.config.js @@ -0,0 +1,37 @@ +import Self from '../../../src'; + +module.exports = { + entry: './index.js', + module: { + rules: [ + { + test: /\.css$/, + use: [ + { + loader: Self.loader, + options: { + publicPath: '', + }, + }, + 'css-loader', + ], + }, + { + test: /\.(svg|png)$/, + use: [ + { + loader: 'file-loader', + options: { + filename: '[name].[ext]', + }, + }, + ], + }, + ], + }, + plugins: [ + new Self({ + filename: '[name].css', + }), + ], +};