Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svg is abstracted from css file. #696

Closed
Evashasha opened this issue Aug 10, 2023 · 3 comments
Closed

Svg is abstracted from css file. #696

Evashasha opened this issue Aug 10, 2023 · 3 comments

Comments

@Evashasha
Copy link

Hi, I've met a problem that encoded svg code was abstracted from its source css file.

The code in source file is like as following馃憞

$alert-primary-color-icon: red;
html{
    background-image: url(./assets/calendar.svg?fill=#{$alert-primary-color-icon});
}

After I run the command npm run build, output files in the destination directory 'dist' are like as following picture.
鎴睆2023-08-10 16 54 38

The repository address is https://github.com/Evashasha/resolve-url-loader-test .

I'm looking forward author's help.馃尮馃尮馃尮

@bhovhannes
Copy link
Owner

Hello,
thank you for putting together a repo for reproducing the issue. That was helpful.

Adding type: 'javascript/auto', to the rule for *.svg files makes things work. I've put the patch which can be applied to your repo below:

Index: webpack.config.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/webpack.config.js b/webpack.config.js
--- a/webpack.config.js	(revision 7884fd3d83e86b887553087a8fe1ca9af4fc150a)
+++ b/webpack.config.js	(date 1691670185129)
@@ -43,6 +43,7 @@
                 ],
             }, {
                 test: /\.svg(\?.*)?$/,  // match img.svg and img.svg?param=value
+                type: 'javascript/auto',
                 use: [
                     {
                         loader: 'svg-url-loader',

This issue is not related to svg-url-loader but rather to how webpack 5 treats assets. This is documented in https://webpack.js.org/guides/asset-modules/ . I don't think I can do something about it inside svg-url-loader.

Because of that, I am closing the issue. The patch written above should help.

@bhovhannes
Copy link
Owner

I believe the last comments in #524 are about similar use case.

@Evashasha
Copy link
Author

I believe the last comments in #524 are about similar use case.

Hello, thank you for putting together a repo for reproducing the issue. That was helpful.

Adding type: 'javascript/auto', to the rule for *.svg files makes things work. I've put the patch which can be applied to your repo below:

Index: webpack.config.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/webpack.config.js b/webpack.config.js
--- a/webpack.config.js	(revision 7884fd3d83e86b887553087a8fe1ca9af4fc150a)
+++ b/webpack.config.js	(date 1691670185129)
@@ -43,6 +43,7 @@
                 ],
             }, {
                 test: /\.svg(\?.*)?$/,  // match img.svg and img.svg?param=value
+                type: 'javascript/auto',
                 use: [
                     {
                         loader: 'svg-url-loader',

This issue is not related to svg-url-loader but rather to how webpack 5 treats assets. This is documented in https://webpack.js.org/guides/asset-modules/ . I don't think I can do something about it inside svg-url-loader.

Because of that, I am closing the issue. The patch written above should help.

many thx~馃尮馃尮馃尮

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants