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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use without html-webpack-plugin ? #12

Open
ryuran opened this issue Aug 2, 2019 · 10 comments
Open

How to use without html-webpack-plugin ? #12

ryuran opened this issue Aug 2, 2019 · 10 comments

Comments

@ryuran
Copy link

ryuran commented Aug 2, 2019

I love you plugin but I have an issue.

I need to insert the svg sprite inline in some html without htmlWebpackPlugin.

By exemple using it in KSS documentation or insert sprite in Html from a php website (webpack is only used to make a bundle of a front module inserted in a bigger php website).

How to do, can we export svgsprite string or insert it by js only ?

@Epimodev
Copy link
Owner

Epimodev commented Aug 2, 2019

Hello !

I haven't use KSS yet so I'm not sure the solution I suggest will work.

I've created another module to create svg sprite without webpack : https://github.com/Epimodev/sprite-svg-symbol
You just need to call this module with the folder containing svg files and it returns a promise with the svg sprite.
Then you can use posthtml (https://github.com/posthtml/posthtml) to inject this sprite in a html file.

For the moment this module doesn't set aria attribute but if this solution solves your problem I can update it.

@ryuran
Copy link
Author

ryuran commented Aug 2, 2019

Hello,
I have try several solution for svg symboles

@Epimodev
Copy link
Owner

Epimodev commented Aug 2, 2019

I haven't try those plugins but according to their documentation I've got same conclusion.

If you want to insert a sprite in a html file without html-webpack-plugin the only solution I've got in mind is to inject the sprite after webpack build.

@ryuran
Copy link
Author

ryuran commented Aug 2, 2019

Yes, same conclusion but svg-sprite-html-webpack do not allow to export sprite as a string variable or as a file.
The only way is by html-webpack-plugin hook.

@Epimodev
Copy link
Owner

Epimodev commented Aug 2, 2019

does an option onSpriteGenerated: (sprite: string) => void which will be a callback with the svg sprite as parameter is a solution which help you in your case ?

@ryuran
Copy link
Author

ryuran commented Aug 5, 2019

Yes I think it can help, I'm not sure it it's enought to work with an othe webpack plugin like kss-webpack plugin because it will create an asynchrone issue.
I think the way to do that is using a webpack hook (but I‘m not sure).

@Epimodev
Copy link
Owner

Epimodev commented Aug 5, 2019

Ok, for the moment this plugin doesn't emits any value for webpack hook.
But I can add a callback and emit a value with webpack hook, even if it doesn't solve your issue it can help other developers which use this plugin.

I'll work on this today or tomorrow.

@Epimodev
Copy link
Owner

Epimodev commented Aug 7, 2019

Hello !

Sorry I've got more work than I expected during last days so I haven't implement callback and webpack hook yet.

But tomorrow I will have the morning to work on this.

@ryuran
Copy link
Author

ryuran commented Sep 23, 2019

const { createSprite } = require('svg-sprite-html-webpack/src/spriteUtils')

I find a way using your createSprite function to get a sprite before webpack build.

@Epimodev
Copy link
Owner

ok happy to read you find a solution.

Sorry, I forgot to add onSpriteGenerated and try to add webpack hook.

I keep this issue open until I make those changes.

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