Skip to content

Commit

Permalink
fix: lack of trailing slash on publicPath string option
Browse files Browse the repository at this point in the history
  • Loading branch information
karlvr committed Apr 5, 2019
1 parent 5db65d2 commit fab158d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export function pitch(request) {
const childFilename = '*'; // eslint-disable-line no-path-concat
const publicPath =
typeof query.publicPath === 'string'
? query.publicPath
? query.publicPath.endsWith('/')
? query.publicPath
: `${query.publicPath}/`
: typeof query.publicPath === 'function'
? query.publicPath(this.resourcePath, this.rootContext)
: this._compilation.outputOptions.publicPath;
Expand Down
2 changes: 2 additions & 0 deletions test/cases/publicpath-trailing-slash/expected/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
body { background: red; background-image: url(/static/img/cd0bb358c45b584743d8ce4991777c42.svg); }

1 change: 1 addition & 0 deletions test/cases/publicpath-trailing-slash/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './style.css';
1 change: 1 addition & 0 deletions test/cases/publicpath-trailing-slash/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/cases/publicpath-trailing-slash/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body { background: red; background-image: url(./react.svg); }
34 changes: 34 additions & 0 deletions test/cases/publicpath-trailing-slash/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const Self = require('../../../');

module.exports = {
entry: './index.js',
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: Self.loader,
options: {
publicPath: '/static/img'
}
},
'css-loader',
],
}, {
test: /\.(svg|png)$/,
use: [{
loader: 'file-loader',
options: {
filename: '[name].[ext]'
}
}]
}
],
},
plugins: [
new Self({
filename: '[name].css',
}),
],
};

0 comments on commit fab158d

Please sign in to comment.