svg-sprite-loader icon indicating copy to clipboard operation
svg-sprite-loader copied to clipboard

Webpack 4 / MiniCssExtractPlugin issue

Open eglaost opened this issue 6 years ago • 12 comments

Is this a bug?

In production mode html markup works fine but css file prints -> background: url(path/from/disk/to/file/mysvg.svg).

It supposed to print: "sprite-467f4d.svg#mysvgid".

In dev mode where i don't use MiniCssExtractPlugin the console log prints the correct url.

Git: https://github.com/eglaost/webpack-boilerplate

  • Node.js version: 8.11.1
  • webpack version: 4.15.1
  • svg-sprite-loader version: 3.8.0
  • OS type & version: Win 10

eglaost avatar Jul 16 '18 18:07 eglaost

Same here.

vortizhe avatar Sep 11 '18 13:09 vortizhe

I try to use 3 css extractors with Webpack 4 with the same results:

  • extract-css-chunks-webpack-plugin
  • mini-css-extract-plugin
  • extract-loader + file-loader

I saw on plugin code it's using optimizeExtractedChunks to hook into extract-text-webpack-plugin to replace the modules so that extractor is the only one who works but is deprecated on Webpack 4.

Maybe the plugin initialization from from the svg loader isn't good approach. It'll be possible to initialize inside css/sass loader chain?.

vortizhe avatar Sep 13 '18 07:09 vortizhe

here I come...

@vortizhe

It should be in the file loader chain. because background images were all in file loader chain, and think about fonts, they are the same.

vicvinc avatar Sep 20 '18 03:09 vicvinc

and if I put the publicPath in SVG-sprite-loader, the SVG path which is been used become 'publicPath/path/to/SVG'.

seems that sprite file name was replaced by the mini-css-extract-plugin.

vicvinc avatar Sep 20 '18 03:09 vicvinc

@kisenka

hi, it's me again.

here Is the same repo, and when building with mini-css-extract-plugin the sprite URL was replaced with the real file path.

just use yarn build:production and you will see it.

here is the result: image

hope helps.

vicvinc avatar Sep 20 '18 10:09 vicvinc

Hey! I'am planning to deprecate and remove extract mode from svg-sprite-loader. To replace it I wrote separate plugin which perform SVG extracting only – extract-svg-sprite-webpack-plugin. Webpack 3 and 4 are supported. It's under heavy development and I suggest you to take part in beta-testing of it. I love my users and want to make them happy! :)

kisenka avatar Sep 27 '18 07:09 kisenka

@vicvinc @vortizhe @eglaost and, of course, I need your feedback, if something going wrong with this plugin.

kisenka avatar Sep 27 '18 11:09 kisenka

@kisenka me, troublemaker is glad to try this. got any situation will be feedback ASAP.

vicvinc avatar Sep 28 '18 02:09 vicvinc

@kisenka, thanks for you work!

I'am planning to deprecate and remove extract mode from svg-sprite-loader. To replace it I wrote separate plugin which perform SVG extracting only – extract-svg-sprite-webpack-plugin

Could you please elaborate?

  1. If extract mode is removed from svg-sprite-loader, what else remains there? I thought it's the main usecase? Does it mean that svg-sprite-loader is going to be deprecated entirely?
  2. Do you recommend to completely switch to extract-svg-sprite-webpack-plugin? I'm asking, because Its weekly downloads counter looks low at npmjs, also there are some bugs (e.g. this PR which fixes a typo is not merged since August: https://github.com/JetBrains/svg-mixer/pull/69/files, also this issue https://github.com/JetBrains/svg-mixer/issues/59 is the 1st thing I see when I try using extract-svg-sprite-webpack-plugin by doing "import i from ".../xyz.svg").

dko-slapdash avatar Oct 01 '19 22:10 dko-slapdash

@kisenka

hi, it's me again.

here Is the same repo, and when building with mini-css-extract-plugin the sprite URL was replaced with the real file path.

just use yarn build:production and you will see it.

here is the result: image

hope helps.

Same to you. And did you found the solution finally?

CodeLittlePrince avatar Jan 07 '20 03:01 CodeLittlePrince

@kisenka, thanks for you work!

I'am planning to deprecate and remove extract mode from svg-sprite-loader. To replace it I wrote separate plugin which perform SVG extracting only – extract-svg-sprite-webpack-plugin

Could you please elaborate?

  1. If extract mode is removed from svg-sprite-loader, what else remains there? I thought it's the main usecase? Does it mean that svg-sprite-loader is going to be deprecated entirely?
  2. Do you recommend to completely switch to extract-svg-sprite-webpack-plugin? I'm asking, because Its weekly downloads counter looks low at npmjs, also there are some bugs (e.g. this PR which fixes a typo is not merged since August: https://github.com/JetBrains/svg-mixer/pull/69/files, also this issue JetBrains/svg-mixer#59 is the 1st thing I see when I try using extract-svg-sprite-webpack-plugin by doing "import i from ".../xyz.svg").

I can't answer all of that, but I removed this plugin an switched to extract-svg-sprite-webpack-plugin and everything now works perfectly

kush1960 avatar Sep 03 '20 16:09 kush1960

Wrote a fix for Webpack 5, so in case you stumble upon this issue or you need inspiration for the fix: https://github.com/JetBrains/svg-sprite-loader/issues/465#issuecomment-990993090

KingSora avatar Dec 10 '21 13:12 KingSora