cascornelissen / svg-spritemap-webpack-plugin

SVG spritemap plugin for webpack
MIT License
207 stars 49 forks source link

webpack dev server support #192

Closed volarname closed 2 years ago

volarname commented 2 years ago

First of all thank you for this great plugin, i tried several one and this one is best working, easy to configure and most up to date.

Description Does it support webpack dev server?

When i have a config with direct files in array like this:

new SVGSpritemapPlugin(
        [
          'src/svgSprite/**/*.svg',
          '../common/src/svgSprite/arrow-up-1.svg',
          '../common/src/svgSprite/fb.svg',
          '../common/src/svgSprite/chevron-right.svg',
          '../common/src/svgSprite/cross-solid.svg',
          '../common/src/svgSprite/cross.svg',
          '../common/src/svgSprite/instagram.svg',
        ],
        {
          output: {
            filename: 'images/svg-sprite.svg',
          },
          sprite: {
            prefix: 'svg-icon-',
            generate: {
              title: false,
            },
          },
          styles: false,
        }
      ),

when i start webpack dev server i get errors in cli:

Watchpack Error (initial scan): Error: ENOTDIR: not a directory, scandir '/var/www/html/common/src/svgSprite/arrow-up-1.svg'
Watchpack Error (initial scan): Error: ENOTDIR: not a directory, scandir '/var/www/html/common/src/svgSprite/fb.svg'
Watchpack Error (initial scan): Error: ENOTDIR: not a directory, scandir '/var/www/html/common/src/svgSprite/chevron-right.svg'
Watchpack Error (initial scan): Error: ENOTDIR: not a directory, scandir '/var/www/html/common/src/svgSprite/cross-solid.svg'
Watchpack Error (initial scan): Error: ENOTDIR: not a directory, scandir '/var/www/html/common/src/svgSprite/cross.svg'

Everything works when i build the project, just watch for changes using webpack dev server is problem. So my question is, does it support webpack dev server? if yes, its a bug? if no how about to add feature to support it?

Thank you

cascornelissen commented 2 years ago

First time I'm seeing someone point to specific files šŸ¤” This could probably be implemented and tested, shouldn't be too hard. The assumption is made here that each input pattern is a directory it seems so we'd need some additional checks there.

https://github.com/cascornelissen/svg-spritemap-webpack-plugin/blob/46d9fd4f081ba4d73bc0fbe6f11ea421648c6a21/lib/index.js#L370

Feel free to submit a PR!

volarname commented 2 years ago

our use case is that we have shared folder with svg files and then we have project specific svg files, so our svg files are not duplicated. we build sprite for each project individually, so we need to reference individual files

cascornelissen commented 2 years ago

I understand and it makes sense, just don't think I've seen anyone before with that use-case. As said, a PR is welcome or I'll look into it myself at some point in the future if I have some time.

volarname commented 2 years ago

take a look, feel free to comment: https://github.com/cascornelissen/svg-spritemap-webpack-plugin/pull/193

cascornelissen commented 2 years ago

I've made some changes in 055d348 that should solve this. Could you try it out on your end by installing directly from master by running the following command?

npm install cascornelissen/svg-spritemap-webpack-plugin#master
volarname commented 2 years ago

I've made some changes in 055d348 that should solve this. Could you try it out on your end by installing directly from master by running the following command?

npm install cascornelissen/svg-spritemap-webpack-plugin#master

i can confirm that this version works without any warning/error and svg sprite file is correctly available in dev server. thank you. when it will land in a release or hotfix officially?

cascornelissen commented 2 years ago

That's great to hear, thanks for the quick reply! I'm hoping to release this together with the fix for #194 but if that takes too long I'll make sure to push out a release āœŒšŸ¼

cascornelissen commented 2 years ago

Just got confirmation the other issue is also solved so I've published version 4.4.1 which includes this fix.