-
-
Notifications
You must be signed in to change notification settings - Fork 387
publicPath can now be a function #373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
098a268
5db65d2
fab158d
a9985d8
0f76012
9ef1de0
1b691ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ import NodeTargetPlugin from 'webpack/lib/node/NodeTargetPlugin'; | |
import LibraryTemplatePlugin from 'webpack/lib/LibraryTemplatePlugin'; | ||
import SingleEntryPlugin from 'webpack/lib/SingleEntryPlugin'; | ||
import LimitChunkCountPlugin from 'webpack/lib/optimize/LimitChunkCountPlugin'; | ||
import validateOptions from 'schema-utils'; | ||
|
||
import schema from './options.json'; | ||
|
||
const MODULE_TYPE = 'css/mini-extract'; | ||
const pluginName = 'mini-css-extract-plugin'; | ||
|
@@ -29,12 +32,19 @@ const findModuleById = (modules, id) => { | |
|
||
export function pitch(request) { | ||
const query = loaderUtils.getOptions(this) || {}; | ||
|
||
validateOptions(schema, query, 'Mini CSS Extract Plugin Loader'); | ||
|
||
const loaders = this.loaders.slice(this.loaderIndex + 1); | ||
this.addDependency(this.resourcePath); | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @evilebottnawi in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @karlvr @evilebottnawi Just wanted to let you know that this introduces a breaking change in the case when the publicPath is set to an empty string meaning that resources are located in the same directory as the css file, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That change was to follow the same behaviour in https://github.com/webpack-contrib/file-loader/blob/master/src/index.js#L37 I'm really sorry about this regression! @evilebottnawi shall we introduce a special case for an empty string here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
: this._compilation.outputOptions.publicPath; | ||
const outputOptions = { | ||
filename: childFilename, | ||
|
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" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
body { background: green; background-image: url(../../cd0bb358c45b584743d8ce4991777c42.svg); } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
body { background: red; background-image: url(../cd0bb358c45b584743d8ce4991777c42.svg); } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
body { background: green; background-image: url(../../react.svg); } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
body { background: red; background-image: url(../react.svg); } |
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', | ||
}), | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
body { background: red; background-image: url(/static/img/cd0bb358c45b584743d8ce4991777c42.svg); } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './style.css'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
body { background: red; background-image: url(./react.svg); } |
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', | ||
}), | ||
], | ||
}; |
Uh oh!
There was an error while loading. Please reload this page.