Skip to content

Commit 582ebfe

Browse files
rmjaevilebottnawi
authored andcommitted
fix(loader): fix publicPath regression (#384)
1 parent f3a6dba commit 582ebfe

File tree

6 files changed

+43
-1
lines changed

6 files changed

+43
-1
lines changed

Diff for: src/loader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function pitch(request) {
6868
const childFilename = '*'; // eslint-disable-line no-path-concat
6969
const publicPath =
7070
typeof options.publicPath === 'string'
71-
? options.publicPath.endsWith('/')
71+
? options.publicPath === '' || options.publicPath.endsWith('/')
7272
? options.publicPath
7373
: `${options.publicPath}/`
7474
: typeof options.publicPath === 'function'

Diff for: test/cases/publicpath-emptystring/expected/main.css

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
body { background: red; background-image: url(cd0bb358c45b584743d8ce4991777c42.svg); }
2+

Diff for: test/cases/publicpath-emptystring/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './style.css';

Diff for: test/cases/publicpath-emptystring/react.svg

+1
Loading

Diff for: test/cases/publicpath-emptystring/style.css

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body { background: red; background-image: url(./react.svg); }

Diff for: test/cases/publicpath-emptystring/webpack.config.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Self from '../../../src';
2+
3+
module.exports = {
4+
entry: './index.js',
5+
module: {
6+
rules: [
7+
{
8+
test: /\.css$/,
9+
use: [
10+
{
11+
loader: Self.loader,
12+
options: {
13+
publicPath: '',
14+
},
15+
},
16+
'css-loader',
17+
],
18+
},
19+
{
20+
test: /\.(svg|png)$/,
21+
use: [
22+
{
23+
loader: 'file-loader',
24+
options: {
25+
filename: '[name].[ext]',
26+
},
27+
},
28+
],
29+
},
30+
],
31+
},
32+
plugins: [
33+
new Self({
34+
filename: '[name].css',
35+
}),
36+
],
37+
};

0 commit comments

Comments
 (0)