Skip to content

Commit 1be21d2

Browse files
fix: allow to use auto value with the publicPath option (#709)
1 parent 470ba0e commit 1be21d2

File tree

11 files changed

+104
-1
lines changed

11 files changed

+104
-1
lines changed

Diff for: src/loader.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,22 @@ export function pitch(request) {
4444
const childFilename = '*';
4545
const publicPath =
4646
typeof options.publicPath === 'string'
47-
? options.publicPath === '' || options.publicPath.endsWith('/')
47+
? options.publicPath === 'auto'
48+
? ''
49+
: options.publicPath === '' || options.publicPath.endsWith('/')
4850
? options.publicPath
4951
: `${options.publicPath}/`
5052
: typeof options.publicPath === 'function'
5153
? options.publicPath(this.resourcePath, this.rootContext)
54+
: this._compilation.outputOptions.publicPath === 'auto'
55+
? ''
5256
: this._compilation.outputOptions.publicPath;
57+
5358
const outputOptions = {
5459
filename: childFilename,
5560
publicPath,
5661
};
62+
5763
const childCompiler = this._compilation.createChildCompiler(
5864
`${pluginName} ${request}`,
5965
outputOptions
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
body {
2+
background: red;
3+
background-image: url(c9e192c015437a21dea1faa1d30f4941.svg);
4+
}
5+

Diff for: test/cases/publicpath-compiler-auto/index.js

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

Diff for: test/cases/publicpath-compiler-auto/react.svg

+1
Loading

Diff for: test/cases/publicpath-compiler-auto/style.css

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

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

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

Diff for: test/cases/publicpath-loader-auto/index.js

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

Diff for: test/cases/publicpath-loader-auto/react.svg

+1
Loading

Diff for: test/cases/publicpath-loader-auto/style.css

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

Diff for: test/cases/publicpath-loader-auto/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: 'auto',
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)