question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to automatically inject extracted svg file?

See original GitHub issue

Do you want to request a feature, report a bug or ask a question? Question.

What is the current behavior? I’ve extracted the svg sprites into separate file and it works, but I still have to manually inject it, and to make it worse, on production, development and Storybook it has to be done on 3 different ways. I’m currently using svg-sprite-injector but it doesn’t work on Storybook.

What is the expected behavior? Generic way to automatically inject path to svg file into the app, so it can be cached.

The best way is to create repo with minimal setup to demonstrate a problem (package.json, webpack config and your code). package.json:

{
    test:    /\.svg$/,
    include: [path.resolve(__dirname, '../src/assets/svg-icons')],
    use:     [
        {
            loader:  'svg-sprite-loader',
            options: {
                extract:        true,
                spriteFilename: 'icons.svg'
            }
        },
        {
            loader:  'svgo-loader',
            options: svgoConfig,
        },
    ],
},

Icon.vue where I’m injecting the svg sprites:

const svgSpriteInjector = require('svg-sprite-injector');
const svgFiles = require.context('@/assets/svg-icons', true, /\.svg$/);
svgFiles.keys().forEach(key => svgFiles(key));
svgSpriteInjector('icons.svg', {revision: 1});

Please tell us about your environment:

  • Node.js version: 8.7.0
  • webpack version: 3.8.1
  • svg-sprite-loader version: 3.4.1
  • OS type & version: Win 10

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nerisinacommented, Feb 18, 2021

Hello, I am having a similar issue with the svg-sprite-loader I am using storybook with vue js Screen Shot 2021-02-18 at 3 26 18 PM

My webpack config looks like this:

{
 test: /\.svg$/,
 loader: 'svg-sprite-loader',
 options: {
   extract: true,
   publicPath: '/'
 }
}

I also check out the git repository from @folmert and the HTML for the SVG isn’t working.

0reactions
nboisteaultcommented, Mar 17, 2020

Hi

In default mode sprite and it’s symbols are part of your JS code, so browser will cache them like other resources.

JS code will change at every new release so if we want efficient cache we need to extract the sprite isn’t it ? It is not clear for me how to load this extracted sprit with webpack then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to unzip files to upload into Cricut Design Space
Click your files you want to add to your canvas. Then click insert images. How to upload SVG cut files into Cricut Design...
Read more >
Extract data in svg file and store automatically in excel
suppose if there are 20 svg files with the same circuit components but with different component values, I need to extract the content...
Read more >
How to extract svg as file from web page - Stack Overflow
15 Answers 15 · Copy the SVG code snippet, and paste it into a new HTML page. · Save the HTML page as...
Read more >
The packages svg and svg-extract - TeXDoc
During the extraction process many files are generated for each SVG file extraction. So it's oftentimes desirable to automatically remove these temporary ...
Read more >
Add multi-density vector graphics - Android Developers
Any auto-generated PNG and XML files corresponding to the deleted vector drawable are removed from the project and the drive. Delivering an app ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found