Skip to content

Commit 3bdd6ac

Browse files
fix: valid generation url() for auto value of the publicPath option
1 parent be7269d commit 3bdd6ac

File tree

9 files changed

+49
-6
lines changed

9 files changed

+49
-6
lines changed

src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function compareModulesByIdentifier(a, b) {
5353
}
5454

5555
const MODULE_TYPE = "css/mini-extract";
56-
const AUTO_PUBLIC_PATH = "__mini_css_extract_plugin_public_path_auto__";
56+
const AUTO_PUBLIC_PATH = "#";
5757
const ABSOLUTE_PUBLIC_PATH = "webpack:///mini-css-extract-plugin/";
5858
const SINGLE_DOT_PATH_SEGMENT =
5959
"__mini_css_extract_plugin_single_dot_path_segment__";
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
body {
2+
background: red;
3+
background-image: url(../../img/bundle/example/react.svg);
4+
}
5+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
background: red;
3+
background-image: url(./example/react.svg);
4+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import path from "path";
2+
3+
import Self from "../../../src";
4+
5+
const PROJECT_DIR = path.resolve(__dirname, "./project");
6+
const SRC_DIR = path.resolve(PROJECT_DIR, "./src");
7+
8+
module.exports = {
9+
entry: {
10+
example: path.resolve(PROJECT_DIR, "./src/example.css"),
11+
},
12+
module: {
13+
rules: [
14+
{
15+
test: /\.css$/,
16+
use: [{ loader: Self.loader }, "css-loader"],
17+
},
18+
{
19+
test: /\.(svg|png)$/,
20+
type: "asset/resource",
21+
generator: {
22+
filename: (pathdata) =>
23+
path.join(
24+
"../../img/bundle/",
25+
pathdata.module.resource.replace(SRC_DIR, "")
26+
),
27+
},
28+
},
29+
],
30+
},
31+
plugins: [
32+
new Self({
33+
filename: "[name].css",
34+
}),
35+
],
36+
};

test/cases/publicpath-auto/expected/webpack-5/styles/f46d3be95d50e953356d/main.css

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/cases/publicpath-auto/webpack.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import Self from "../../../src";
22

33
module.exports = {
44
entry: "./index.js",
5+
optimization: {
6+
realContentHash: true,
7+
},
58
module: {
69
rules: [
710
{

0 commit comments

Comments
 (0)