Giter Club home page Giter Club logo

Comments (22)

cascornelissen avatar cascornelissen commented on June 2, 2024 5

Yeah, you might want to try the .source() function, as variables prefixed with a _ are private by convention:

<%= compilation.assets["spritemap.svg"].source() %>

from svg-spritemap-webpack-plugin.

cascornelissen avatar cascornelissen commented on June 2, 2024 1

Looks like we were thinking the same thing, I've just added a minimal inline-html example to the repository. Great to hear it's working with 3.4.0 for you as well!

from svg-spritemap-webpack-plugin.

cascornelissen avatar cascornelissen commented on June 2, 2024

In what way? Are you using something like html-webpack-plugin?

from svg-spritemap-webpack-plugin.

borm avatar borm commented on June 2, 2024

yes

from svg-spritemap-webpack-plugin.

cascornelissen avatar cascornelissen commented on June 2, 2024

The generated spritemap ends up in the webpack assets with a chunk name, this should allow you to target it when using a custom template, see this example for more info.

from svg-spritemap-webpack-plugin.

borm avatar borm commented on June 2, 2024

Don`t understand,
where chunk output
how i should require it

<%= require('html-loader!../spritemap') %>

from svg-spritemap-webpack-plugin.

cascornelissen avatar cascornelissen commented on June 2, 2024

@borm, read the docs for html-webpack-plugin, it's in there, I don't really use it myself so I can't really help you. It's possible to target files or custom options in an .ejs file like this:

<% htmlWebpackPlugin.files %>

It should also be possible to get the source content of a file/asset via the compile.assets[] array and the source() function:

<%= compilation.assets[??].source() %>

from svg-spritemap-webpack-plugin.

borm avatar borm commented on June 2, 2024
new SVGSpritemapPlugin({
      src: ['src/icons/*.svg', 'src/icons/flags/*.svg'],
      filename: 'dist/sprite.svg',
      prefix: 'icon-',
      chunk: 'spritemap',
      deleteChunk: false,
      styles: path.join(__dirname, 'src/_sprites.scss'),
    }),
<pre>
  <%= JSON.stringify(htmlWebpackPlugin.files, 0, 2) %>
</pre>

output

{
--
  | "publicPath": "",
  | "chunks": {
  | "vendors~app": {
  | "size": 1763912,
  | "entry": "dist/vendors~app.js",
  | "hash": "e5ac2dc6a01f80ebfe1b",
  | "css": [
  | "dist/vendors~app.css"
  | ]
  | },
  | "app": {
  | "size": 653824,
  | "entry": "dist/app.js",
  | "hash": "31d69e6c1451af924090",
  | "css": [
  | "dist/app.css"
  | ]
  | }
  | },
  | "js": [
  | "dist/vendors~app.js",
  | "dist/app.js"
  | ],
  | "css": [
  | "dist/vendors~app.css",
  | "dist/app.css"
  | ]
  | }

from svg-spritemap-webpack-plugin.

cascornelissen avatar cascornelissen commented on June 2, 2024

@borm, can you also post the entire webpack output and the output of the following code in the ejs template?

<pre>
  <%= JSON.stringify(compilation.assets, 0, 2) %>
</pre>

from svg-spritemap-webpack-plugin.

borm avatar borm commented on June 2, 2024

veeeeeery big output

from svg-spritemap-webpack-plugin.

cascornelissen avatar cascornelissen commented on June 2, 2024

Haha, I would've guessed. You can add it as an attachment if you want to?

from svg-spritemap-webpack-plugin.

borm avatar borm commented on June 2, 2024

r.txt

from svg-spritemap-webpack-plugin.

borm avatar borm commented on June 2, 2024

ah, i see "spritemap.svg"

from svg-spritemap-webpack-plugin.

borm avatar borm commented on June 2, 2024

as i understood i can use it
<%= compilation.assets["spritemap.svg"]._value %>

from svg-spritemap-webpack-plugin.

borm avatar borm commented on June 2, 2024

but why it not exist inside htmlWebpackPlugin.files :(

from svg-spritemap-webpack-plugin.

cascornelissen avatar cascornelissen commented on June 2, 2024

No idea why it doesn't show up when printing the array but if it works it works, right?

from svg-spritemap-webpack-plugin.

borm avatar borm commented on June 2, 2024

yes

from svg-spritemap-webpack-plugin.

borm avatar borm commented on June 2, 2024

Up, how get it in version 3.3.5

new SVGSpritemapPlugin('src/icons/!*.svg', {
      output: {
        filename: 'dist/sprite.svg',
        chunk: {
          name: 'spritemap',
          keep: true,
        },
      },
      sprite: {
        prefix: 'icon-',
        gutter: 8,
        generate: {
          title: false,
        },
      },
      styles: false,
    }),

<%= JSON.stringify(compilation.assets["dist/sprite.svg"], 0, 2) %>
<%= JSON.stringify(compilation.assets["spritemap.svg"], 0, 2) %>
<%= JSON.stringify(compilation.assets["spritemap"], 0, 2) %>
Nothing printed

<%= JSON.stringify(htmlWebpackPlugin.files, 0, 2) %>


{
--
  | "publicPath": "",
  | "js": [
  | "dist/vendors~app.js",
  | "dist/app.js"
  | ],
  | "css": [
  | "dist/vendors~app.css",
  | "dist/app.css"
  | ]
  | }


from svg-spritemap-webpack-plugin.

cascornelissen avatar cascornelissen commented on June 2, 2024

@borm, can you confirm that it works with 3.4.4? It might be related to changes made in #79.

from svg-spritemap-webpack-plugin.

borm avatar borm commented on June 2, 2024

@cascornelissen maybe you mean 3.4.0?

don`t worked

from svg-spritemap-webpack-plugin.

cascornelissen avatar cascornelissen commented on June 2, 2024

@borm, no I meant 3.3.4, sorry for the typo. The changes introduced by #79 were released in 3.3.5 so I was wondering if it was related to that. But also some more fixes were added and released in 3.3.6, 3.3.7 and 3.4.0. Can you also check the latest version if 3.3.4 works?

from svg-spritemap-webpack-plugin.

borm avatar borm commented on June 2, 2024

3.3.4 works

sorry but 3.4.0 also works

Can you add this example https://github.com/borm/webpack-spritemap to examples?

from svg-spritemap-webpack-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.