-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: publicPath can be a function (#373)
- Loading branch information
1 parent
272910c
commit 7b1425a
Showing
15 changed files
with
189 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"additionalProperties": true, | ||
"properties": { | ||
"publicPath": { | ||
"anyOf": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"instanceof": "Function" | ||
} | ||
] | ||
} | ||
}, | ||
"errorMessages": { | ||
"publicPath": "should be {String} or {Function} (https://github.com/webpack-contrib/mini-css-extract-plugin#publicpath)" | ||
}, | ||
"type": "object" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
test/cases/publicpath-function/expected/nested/again/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
body { background: green; background-image: url(../../cd0bb358c45b584743d8ce4991777c42.svg); } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
body { background: red; background-image: url(../cd0bb358c45b584743d8ce4991777c42.svg); } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
body { background: green; background-image: url(../../react.svg); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
body { background: red; background-image: url(../react.svg); } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const Self = require('../../../'); | ||
const path = require('path') | ||
|
||
module.exports = { | ||
entry: { | ||
// Specific CSS entry point, with output to a nested folder | ||
'nested/style': './nested/style.css', | ||
// Note that relative nesting of output is the same as that of the input | ||
'nested/again/style': './nested/again/style.css', | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: [ | ||
{ | ||
loader: Self.loader, | ||
options: { | ||
// Compute publicPath relative to the CSS output | ||
publicPath: (resourcePath, context) => path.relative(path.dirname(resourcePath), context) + '/', | ||
} | ||
}, | ||
'css-loader', | ||
], | ||
}, { | ||
test: /\.(svg|png)$/, | ||
use: [{ | ||
loader: 'file-loader', | ||
options: { | ||
filename: '[name].[ext]' | ||
} | ||
}] | ||
} | ||
], | ||
}, | ||
plugins: [ | ||
new Self({ | ||
filename: '[name].css', | ||
}), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
body { background: red; background-image: url(/static/img/cd0bb358c45b584743d8ce4991777c42.svg); } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './style.css'; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
body { background: red; background-image: url(./react.svg); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}), | ||
], | ||
}; |