Comments (23)
@maximryabov22011988 I checked your webpack config but I couldn't find anything wrong with it. On which browsers are you experiencing this problem?
from external-svg-sprite-loader.
This issue occurred in Chrome latest version. I was very surprised by this problem, maybe, already worked with svg and use when making sites. Have you tried making the production assembly and then opening index.html in the dist folder? And everything opened as expected?
from external-svg-sprite-loader.
Or do I just need to make a production assembly and upload the contents of the dist folder somewhere to the server? Maybe I'm doing something wrong ?!
from external-svg-sprite-loader.
I am not able to build your assets. I followed the following steps:
- Cloned your repo
- Run
npm i
- Run
npm run build
and got the following error:
ERROR in ./src/index.js
Module not found: Error: Can't resolve './components/base/Icon' in '/Users/bensampaio/Downloads/webpack-broker-master/src'
@ ./src/index.js 3:0-42 8:71-75
from external-svg-sprite-loader.
I'm sorry. I updated the production build. Now it works. And i deploy production build
to gh-pages: https://maximryabov22011988.github.io/webpack-broker/
from external-svg-sprite-loader.
And fixed this error:
ERROR in ./src/index.js Module not found: Error: Can't resolve './components/base/Icon' in
from external-svg-sprite-loader.
Sprite in url(background-image) work correctly. But sprite in html with USE tag don't work. In production build i use publicPath ../
. Maybe this is the reason?
In development mode i use publicPath /
and sprite in html and in background-image work correctly. But such publicPath don't work in production mode
from external-svg-sprite-loader.
@maximryabov22011988 that's definitly the reason. If you check the network tab in the Chrome inspector you'll see an error loading the sprive.svg file. The browser is trying to load "https://maximryabov22011988.github.io/images/sprite.svg" which doesn't exist. What you want is: "https://maximryabov22011988.github.io/webpack-broker/images/sprite.svg". So I don't think you need to change the publicPath
at all. Why are you using ../
?
from external-svg-sprite-loader.
After compiling the production build, sprite file put in the image folder and app.css file is in the css folder. If i remove the public path '../', then the sprite in the background-image stops working. And the sprite in html still does not work.
Structure dist folder after production build:
- index.html
- css
- images
- js
- favicon
css, js, images, favicon are folders
from external-svg-sprite-loader.
The publicPath
option refers to a URL path not a file system path so when you use ../
you are trying to get something from outside your application scope. Your configuration looks very much like mine so I think that you don't even need to set the publicPath
option. Did you try that?
If that doesn't work then I would say you need to set the publicPath
to /images/
but I really think you don't need this option at all. This option is only there for when your assets are placed in a CDN.
from external-svg-sprite-loader.
I made the dist folder structure more flat. Sprite in html is now loaded without error, but not displayed.
Under the development mode, the sprite in the html and the css works correctly (https://prnt.sc/qk19jm).
In production mode, the css is displayed correctly, but the html, although it has loaded, isn't displayed (https://prnt.sc/qk1dde)
from external-svg-sprite-loader.
I found a problem place ... There seems to be a problem with the id
mismatch. SVG uses this id http://prntscr.com/qk1sro
But in the sprite itself there is no such name id
https://prnt.sc/qk1tup. What else is happening here is minification. What do you think could be the problem?
from external-svg-sprite-loader.
Yes, I tried it completely without this option publicPath
, but this, unfortunately, did not solve the problem.
from external-svg-sprite-loader.
I tried to clone your repo again and managed to fix your issue locally by changing webpack/loaders/svgSprite.js
to the following:
const SvgStorePlugin = require('external-svg-sprite-loader');
module.exports = (env) => ({
loader: SvgStorePlugin.loader,
options: {
name: 'images/sprite.svg',
iconName: '[name]-[hash:6]',
},
});
Can you confirm that this works?
from external-svg-sprite-loader.
After changing the structure, the sprite began to load with gh-pages
. Now app.css
, app.js
, sprite.svg
put to the root of the project, where index.html
lies
from external-svg-sprite-loader.
For some reason, everything works on the dev server. But gh-pages are not. Although there are no file upload errors
from external-svg-sprite-loader.
#72 (comment)
Yes, it is work!!!
I found a problem place ... There seems to be a problem with the id
mismatch. SVG uses this id http://prntscr.com/qk1sro
But in the sprite itself there is no such name id
https://prnt.sc/qk1tup. What else is happening here is minification.
This behavior can be seen at https://maximryabov22011988.github.io/webpack-broker/
On the dev server in the sprite have the correct id
. In html - http://prntscr.com/qk7fby, in sprite - http://prntscr.com/qk7ftf
What do you think could be the problem?
from external-svg-sprite-loader.
Maybe the problem is that I set mode: 'production' in the webpack config and the svgo plugin minifies the id? In development mode id don't minify.
from external-svg-sprite-loader.
I looked into it but so far I don't understand the issue. I use this plugin in production and never found this problem. Minification is only done per symbol in the sprite by the loader. Are you minifying the sprite as well?
from external-svg-sprite-loader.
Now I turned off the minification of the svg. Now the problem is that after production build and deploy to gh-pages production, the sprite, although it is in the markup, is not displayed (screenshot - https://drive.google.com/file/d/1Vl-7PM1rj3h3j-Q9dpMkhC6nirCnYvPb/view?usp=drivesdk )
Now the problem is reproducing on
https://maximryabov22011988.github.io/webpack-broker/
Alfa icon don't displayed
https://prnt.sc/qk1sro
although the sprite loaded without errors
At the same time, the Alpha icon is displayed on the dev server.
What do you think it could be?
from external-svg-sprite-loader.
It seems that the viewbox
attribute of your svg
elements is set to undefined
. I noticed in your webpack config that you changed the svgo configuration. svgo removes the viewports by default but that is required for this loader to work. So you should make sure that { removeViewBox: false }
is part of your svgo config.
In short your config should look like this:
{
loader: SvgStorePlugin.loader,
options: {
name: 'images/sprite.svg',
iconName: '[name]-[hash:6]',
svgoOptions: {
plugins: [{ cleanupIDs: false }, { removeUnknownsAndDefaults: false }, { removeViewBox: false }],
},
},
}
I added this to the README to make more clear how to configure SVGO.
from external-svg-sprite-loader.
Thanks a lot!!!! You helped me a lot! It all worked! Thanks for the great plugin!
from external-svg-sprite-loader.
No problem! I'm happy it all worked out! Happy spriting!
from external-svg-sprite-loader.
Related Issues (20)
- Clearer errors when trying to use the latest version with Webpack 4
- Duplicated IDs in icon sprite
- angular13 not generate sprite file
- It doesn't work with webpack 5 cache=filesystem
- SVGO Options HOT 4
- "TypeError: loaders is not iterable" after upgrade to v4 HOT 8
- Odd behavior when generating a manifest file HOT 8
- consistency with others loaders in manifest.json HOT 4
- Error when defining Rule.use as a function HOT 2
- Using `webpack-chain` breaks default options HOT 1
- It doesn't generate svg sprite HOT 17
- The module removes "fill" attribute when converting to symbol HOT 2
- Alternative (simpler) way to address the images inside the sprite (no math) HOT 1
- deprecation warning for chunk.files in webpack 5 HOT 1
- Can't run in storybook
- Deprecation warning for Chunk.modulesIterable
- Breaks with [email protected] HOT 3
- SvgStorePlugin fails if there are any other unrelated errors in the build HOT 1
- Support and compatibility with Webpack 4 regarding mini-css-extract-plugin HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from external-svg-sprite-loader.