Code Monkey home page Code Monkey logo

svg-sprite's Introduction

SVG Sprite Module

npm (scoped with tag) npm

Optimized and Easy way to use SVG files in Nuxt

Sprites help increase speed, maintain a consistent development workflow, and make the creation of icons much faster. SVG sprites are typically created using icons of a similar shape or form whereas larger scale graphics are one-off applications.

Demo: https://codesandbox.io/s/github/nuxt-community/svg-sprite-module/

โš ๏ธ NOTE: SVG Sprites does not work on IE, if you wish to support IE you could use svg4everybody. Take a look at this issue to see how.

๐ŸŒˆ NOTE: If you wish to load single SVG icon and you don't want to create sprites, use Nuxt SVG Module. SVG module for Nuxt.js, allows you to import .svg files in multiple ways depending on the resource query you provide.

Installation

yarn add @nuxtjs/svg-sprite
# or
npm i @nuxtjs/svg-sprite

Usage

Add @nuxtjs/svg-sprite to modules section of nuxt.config:

export default defineNuxtConfig({
  modules: [
    '@nuxtjs/svg-sprite',
  ],
  svgSprite: {
    // manipulate module options
  }
})

Place your svg files in ~/assets/sprite/svg/, say sample.svg and use your image with globally registered svg-icon component:

<svg-icon name="sample" />

To create different sprites, create custom directory inside ~/assets/sprite/svg/ and put your svg files inside it and place directory tile before icon name (example: ~/assets/sprite/svg/my-sprite/my-image.svg):

<svg-icon name="my-sprite/my-image" />

Module create a page that list all of icons for you, by default you can see this page in /_icons path.
Note: This page creates in dev mode, So you can't see it in production.

Options

Module default options:

Option Default Description
input ~/assets/sprite/svg Directory of original svg files
output ~/assets/sprite/gen Directory to store generated sprites
defaultSprite icons Name of default sprite (default sprite consist of all svgs that place directly inside input directory)
elementClass icon global class of all <svg-icon> instances
spriteClassPrefix sprite- Prefix of sprite specific classes
publicPath null Specifies a custom public path for the sprites
iconsPath _icons Custom path for icons list page (In order to disable this page, pass false or null to this option)
svgoConfig null Custom config object for SVGO, How to customize SVGO config

You can update them with the svgSprite option in nuxt.config:

export default defineNuxtConfig({
  modules: ['@nuxtjs/svg-sprite'],
  svgSprite: {
    input: '~/assets/svg/'
  }
}

Props

Prop Description
name icon path with format SPRITE_NAME/ICON_NAME, SPRITE_NAME can be omitted for default sprite
title Accessibility title for icon, this props will transform to <title> tag inside <svg>
desc Accessibility description for icon, this props will transform to <desc> tag inside <svg>

Integrations

Storybook

This module provides a story to list and search available icons of your project. You can see stories under stories directory. If you are using @nuxtjs/storybook you can see the SvgSprites stories under Modules section in your storybook. Sprites will show in your Storybook, unless you disable/hide the story using Storybook's modules option

Development

  • Clone this repository
  • Install dependencies using yarn install or npm install
  • Start development server using npm run dev

You can also contribute directly with CodeSandBox: https://codesandbox.io/s/github/nuxt-community/svg-sprite-module/

License

MIT License Copyright (c) Nuxt Community - Ahad Birang

svg-sprite's People

Contributors

andrewvasilchuk avatar atinux avatar dependabot[bot] avatar farnabaz avatar haan123 avatar harlan-zw avatar ilya-buligin avatar jubeiam avatar lennoximus avatar obennaci avatar pi0 avatar renovate-bot avatar renovate[bot] avatar robikovacs avatar tomaszal avatar troalexis avatar twxia avatar yurks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

svg-sprite's Issues

How to use svg's original size ?

Hya, thanks for this great lib, I have an issue where I would like to use the original size svg
If I set the width and height to unset or initial the inner svg is in the correct size (the one in the shadow root) but the outer html is much larger

example:

inner svg

image
image

As you can see its in the correct size but if you look at the outer one
image
image

Is there a way to fix this ?

What is a proper way of using this lib in a monorepo?

I want to use svg-sprite-module in a monorepo, so icons would reside in it's own independent project that produces a sprite file that can be reused throughout different projects. So I wonder what would be the best way to implement such architecture?
Of course someone could ask me: "Why do you need nuxt dependency in such project at all?" - And maybe would be right, but to me Nuxt is firstly - a great dev UX so I would like to keep using it for a pleasure of comfortable dev UX process even when it's only for the purpose of building icons.

One thing I already understand - I can't rely on the generated component since the only outcome of the project would be agnostic svg sprite file and all subsequent implementation should happen in a repo that would use this file. So I decided to build an <svg-icon> component from scratch. It will look something like this:

<template>
  <svg class="svg-icon"
       :class="[{'icon-flipped':flipped}, dir && `svg-icon-${dir}`]"
       :width="size"
       :height="size">
    <use :href="`./icons.svg#i-${name}`" :xlink:href="`./icons.svg#i-${name}`"/>
  </svg>
</template>

<script>
  export default {
    name: 'Icon',
    props: {
      name: {
        type: String,
        required: true
      },
      size: {
        type: [String, Number],
        default: '16'
      },
      dir: {
        type: String
      },
      flipped: {
        type: Boolean,
        default: false
      }
    }
  }
</script>

<style lang="scss">
  .svg-icon {
    flex-shrink: 0;

    &-down {
      transform: rotate(90deg);
    }

    &-up {
      transform: rotate(-90deg);
    }

    &-left {
      transform: rotate(-180deg);
    }
  }
</style>

and it's kinda work, my only concern right now is caching - I guess I can't rely on the built in generated file that is placed into a /_nuxt/ folder but rather add version string to a file that resides in a static folder, something like ./icons.svg?v=1

@farnabaz what do you think about all of this? :) Maybe you could recommend something that can improve such use case?

Need help with config

Hi.
Can you tell me what I'm doing wrong?

I want to take the sources from ~/assets/svg/ and put the generated file in ~/static/svg
But I encountered a problem:
1 the .gitignore file is Added
2. Not modified\removed the prefix i-
3. Automatically populated width and height

My config:

svgSprite: { input: "~/assets/svg/", output: "~/static/svg", defaultSprite: "sprite", spriteClassPrefix: "", }

In finally i want use

<svg> <use xlink:href="~/static/svg/sprite.svg#reload"></use> </svg>
where reload it's symbol's id.
thx

SVGs are base64 inlined in the generated JS bundle

Heyooo. ๐Ÿ‘‹๐Ÿป Thanks so much for this package. I just implemented it and it worked great! ๐Ÿ‘๐Ÿป๐ŸŽ‰

I noticed a tiny thing. I ran bundle analyzer on my nuxt site and discovered that the icons are inlined in the generated JavaScript files.

screenshot 2019-02-10 22 01 26

To be sure I removed the module again which made the inlined assets disappear.

screenshot 2019-02-10 22 02 10

This is e.g. code that is generated:

/***/ "./assets/icons/stopwatch.svg":
/*!************************************!*\
  !*** ./assets/icons/stopwatch.svg ***!
  \************************************/
/*! no static exports found */
/***/ (function(module, exports) {

module.exports = "data:image/svg+xml;base64,PHN2ZyBmaWxsPSIjMUQ3Q0JCIiB3aWR0aD0iMTAwIiBoZWlnaHQ9IjEwMCIgdmlld0JveD0iMCAwIDEwMCAxMDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTgxLjAzMSAzOC4zMDVsNi01LjIzNC01LjA4Ni01LjgzMi02LjAwOCA1LjIzOGEzOS4xNDMgMzkuMTQzIDAgMCAxIDUuMDk0IDUuODI4em0tMjcuNjY4LTEyLjIzVjE4LjExaDcuNzM4VjYuNTAxSDM3Ljg4NnYxMS42MWg3LjczOXY3Ljk2NGMtMTcuNDEgMS45MjYtMzAuOTU3IDE2LjY3Ni0zMC45NTcgMzQuNTk4IDAgMTkuMjM0IDE1LjU5NCAzNC44MjQgMzQuODI0IDM0LjgyNCAxOS4yMzQuMDA0IDM0LjgyOC0xNS41OSAzNC44MjgtMzQuODIgMC0xNy45MjYtMTMuNTQzLTMyLjY3Mi0zMC45NTctMzQuNjAyem0tMy44NzEgNjEuNjg4Yy0xNC45NjEgMC0yNy4wODYtMTIuMTI1LTI3LjA4Ni0yNy4wODYgMC0xNC45NjEgMTIuMTI1LTI3LjA4NiAyNy4wODYtMjcuMDg2IDE0Ljk2IDAgMjcuMDg2IDEyLjEyNSAyNy4wODYgMjcuMDg2LjAwNCAxNC45NjEtMTIuMTI1IDI3LjA4Ni0yNy4wODYgMjcuMDg2em0zLjg3MS00Ni40MzhoLTcuNzM4djIzLjIxOWgxOS4zNDh2LTcuNzM4aC0xMS42MXoiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvc3ZnPg=="

Is this expected behavior? I'm assuming this is the result of some webpack default settings?

I'm not using these inlined files and would like to save the 20kb. ( not a big deal but hey ;) )

Keep up the good work and thanks a bunch!

I'm also happy to look into it myself. ๐Ÿ˜Š

Allow to set a class to the use tag inside the svg-icon component

Hello. The external svg file appears in the document inside the closed shadow dom, when we require it via use tag. This doesn't allow us to customize the svg style using css, but it's still can be done by applying a class to the use tag. Please add a property to the svg-icon component, so we could apply a class to the svg inside shadow dom. Some details are described here: https://tympanus.net/codrops/2015/07/16/styling-svg-use-content-css/.
Thank you.

Inline the SVG and prevent load from sprite

Sometimes we need to inline the svg to prevent blinking and increase the lighthouse scoring when the svg is visible at render time. Is there any option to take the svg from the generated sprite and inline it instead of including it using the <svg><use xlink:href="#id"></use></svg> method? It would be fantastic to have a <svg-icon name="icon-name" inline="true" /> option or similar. A workaround is to use the url-loader plugin but it would be greatter to use the svgo optimized version from the generated sprite. Any ideas?

Thank you!

Set input to node_modules folder

I've got icons from a pattern library that I've installed via NPM, so I'd like to point my input folder at that folder, but whenever I do, I get an empty gen folder. There's no error, but I'm assuming it's not able to find my input folder. What am I doing wrong?

  svgSprite: {
    input: 'lts-patterns/dist/images/icons',
  },

Cannot read property 'split' of undefined

This page contains the SVG display that works without refreshing F5, but after you want to refresh F5, the image is shown as follows:
image

Because the single page in my project introduces the <svg-icon /> prop name binding to get the value from the calculated property

<template>
  <div>
  ...
    <svg-icon :name="osIconName" />
  ...
  </div>
<template>

export.default(){
...
 props: {
    ua: {
      type: String,
      default: ''
    }
 },
 computed:{
  usResult () {
      return usParser(this.ua);
  },
  osIconName() {
      const osName = this.usResult.result.os.name;
      return osName;
   },
  }
...
}

How to solve this problem so that I can hit refresh F5 after normal work

How to set svgo plugin options

I want to use variables css on transform like <path transform="var(--transform)" d="..."/>, but get NaN path for attribute d.

I think that the probable cause is svgo plugin settings "convertTransform".
Is there any option to set it?

SVG File
image

Output
image

Empty sprite after build

Hello, thanks for this nice tool, but it works for me only in dev mode. When I build my project then sprite generates without any icons (in development everything is OK, sprite generates perfectly). I just follow the main guide and I don't know why it happens, I hope anyone can help me.

Below I provide screenshots which may be helpful:

My modules in nuxt.config.js:

image

File structure:

image

icons.svg file:

image

build:

image

image

image

Don't Ignore all files or directories in output directory?

Hello, Thank you for useful nuxt module!

I want to gitignore only file such as icons.svg not *.
For example, I set options to nuxt.config.js like:

svgSprite: {
  input: "~/assets/svg/icons",
  output: "~/assets/svg",
  defaultSprite: "icon-sprite"
}

All icon files in ~/assets/svg/icons will be also ignored because .gitignore has *.
Only I can do is change directory structure?
thank you

How do I style an individual path in an SVG with CSS?

image

The SVG is hidden inside shadow-root.

I have some SCSS, that I want to change the colour of each path when the SVG is hovered:

svg {
  &:hover {
    path {
      &:nth-child(1) {
        fill: #00C58E;
      }

      &:nth-child(2) {
        fill: #2F495E;
      }

      &:nth-child(3) {
        fill: #108775;
      }
    }
  }
}

But this doesn't work because of shadow-root. What's the best way to achieve this? ๐Ÿ™‚

Version on npm differs from github version.

Hi!

I found an issue with svg-sprite-module that seems to have been fixed in the repo. But the fix does not reflect in the same version on npm. Both versions being v0.4.10.

See here (line 11): icons-list.vue @ npm.runkit.com

It still says:key="symbol" vs. :key="symbol.path" as was fixed in 6cde160.

I have no idea how that can happen but I'd be very happy if you could look into this.

Thanks in advance!

Custom input/output path brakes building process

How to reproduce:
Specify the custom path for input/output property, e.g. :
input: ~/static/icons/svg
output: ~/static/icons/gen

Actual Result:
Build fails with an error:

~/assets/sprite/gen/sprites.json in ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./node_modules/@nuxtjs/svg-sprite/lib/pages/icons-list.vue?vue&type=script&lang=js&

Expected result:
Build should compile successfully

This issue is caused by the fact that the sprite path is hardcoded in icon-list.vue to ~/assets/sprite/gen/sprites.json. This path should reflect an output path instead

IE11 support

Hi, is there a way to make this work in IE11? Right now it just fails

Allow setting of a global class to the `svg-icon` element

I was thinking it could probably be useful to receive class as a prop and add it to the svg-icon component so we can style it globally.

Currently, the first solution I see is to wrap svg-icon into another component (ie <foo-icon>) and use it in every template. However, I believe this could be solved trivially.

I'd like to propose some API that allows this to be set on initialisation:

svgSprite: {
    input: '~/assets/sprite/svg',
    output: '~/assets/sprite/gen',
    defaultSprite: 'icons',
    elementClass: 'icon'
  }

This will allow the icons to share a global style and we already have the generated id for individual style.

I came across this problem when (naively) styling the svg element globally which led to weird behaviours when scaling

Do you consider this is worth it? Maybe I'm missing some obvious solution.

symbols tags are being rendered outside defs tags

Hi all, thanks for the amazing plugin.
I just realised that the <symbol> is being rendered outside the <defs>. I'm not shure it's a bug or an expected behavior, but AFAIK they should be inside the <defs>.

<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>

</defs>
<symbol id="i-activity">
  <path d="M11.961 3.336a.668.668 0 00-.592.448l-.001.005-3.849 11.544H2.667a.667.667 0 100 1.334H8a.667.667 0 00.631-.451l.001-.005 3.367-10.102 7.367 22.101a.668.668 0 001.264.005l.001-.005 3.849-11.544h4.852a.667.667 0 100-1.334h-5.333a.667.667 0 00-.631.451l-.001.005L20 25.89 12.633 3.789a.668.668 0 00-.632-.454l-.042.001h.002z"/>
</symbol>  
</svg>

Version: 0.4.11

Defs inside symbols

Hola!

If you have an svg icon like this:

<svg width="126" height="47" xmlns="http://www.w3.org/2000/svg"> <defs> <linearGradient x1=".258%" y1="49.75%" x2="101.258%" y2="49.75%" id="a"> <stop stop-color="#E94E8E" offset="0%"/> <stop stop-color="#30AA93" offset="21.532%"/> <stop stop-color="#312783" offset="43.368%"/> <stop stop-color="#F39CBF" offset="63.182%"/> <stop stop-color="#2A99C5" offset="80.568%"/> <stop stop-color="#6DCCD1" offset="100%"/> </linearGradient> </defs> <path d="M66.465 260.939c18.853 0 20.853 37.706 39.706 37.706s20.853-37.706 39.706-37.706 18.853 37.706 37.706 37.706" transform="translate(-62 -256)" stroke="url(#a)" stroke-width="8" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"/> </svg>

The generated svg :

<svg xmlns="http://www.w3.org/2000/svg" id="i-wave1" width="100%" height="100%"><path d="M66.465 260.939c18.853 0 20.853 37.706 39.706 37.706s20.853-37.706 39.706-37.706 18.853 37.706 37.706 37.706" transform="translate(-62 -256)" stroke="url(#wave1-a)" stroke-width="8" fill="none" stroke-linecap="round" stroke-linejoin="round"></path></svg>

Module cuts defs.

Thanks!

Issue on Zeit now.sh

Call stack:

FATAL  Cannot find module 'chokidar'
Require stack:
- /var/task/node_modules/@nuxtjs/svg-sprite/lib/module.js
- /var/task/node_modules/@nuxt/core/dist/core.js
- /var/task/now__launcher.js
- /var/runtime/UserFunction.js
- /var/runtime/index.js
  Error: Cannot find module 'chokidar'
  Require stack:
  - node_modules/@nuxtjs/svg-sprite/lib/module.js
  - node_modules/@nuxt/core/dist/core.js
  - now__launcher.js
  - /var/runtime/UserFunction.js
  - /var/runtime/index.js
  at Object.<anonymous> (node_modules/@nuxtjs/svg-sprite/lib/module.js:1)
2020-03-08T16:41:14.031Z	undefined	ERROR	ฮป Error while initializing nuxt: /var/task/node_modules/@nuxtjs/svg-sprite/lib/module.js:1

Error after upgrading (ENOENT: no such file or directory ...)

Howdy! After updating to the latest version, it happens something similar to #120.

My dev output is:

 ERROR  ENOENT: no such file or directory, open '.../nuxt-application/.nuxt/nuxt-svg-sprite-icons-list.vue'

  at Object.openSync (fs.js:440:3)
  at readFileSync (fs.js:342:35)
  at exports.extractComponentOptions (node_modules/nuxt-i18n/src/helpers/components.js:12:45)
  at buildLocalizedRoutes (node_modules/nuxt-i18n/src/helpers/routes.js:31:21)
  at exports.makeRoutes (node_modules/nuxt-i18n/src/helpers/routes.js:135:46)
  at Object.<anonymous> (node_modules/nuxt-i18n/src/index.js:68:33)
  at Object.extendRoutes (node_modules/@nuxt/utils/dist/utils.js:1817:17)
  at Builder.resolveRoutes (node_modules/@nuxt/builder/dist/builder.js:5836:50)
  at async Promise.all (index 1)
  at async Builder.generateRoutesAndFiles (node_modules/@nuxt/builder/dist/builder.js:5664:5)
  at async Builder.build (node_modules/@nuxt/builder/dist/builder.js:5589:5)
  at async Object._buildDev (node_modules/@nuxt/cli/dist/cli-dev.js:98:5)
  at async Object.startDev (node_modules/@nuxt/cli/dist/cli-dev.js:56:7)
  at async Object.onWatchRestart (node_modules/@nuxt/cli/dist/cli-dev.js:122:5)
  at async Nuxt.callHook (node_modules/hable/lib/hookable.js:50:7)
  at async FSWatcher.<anonymous> (node_modules/@nuxt/builder/dist/builder.js:6172:9)

I am using nuxt 2.10.2 and nuxt-i18n 6.4.1 and my setup is very straightforward (It works perfectly with <= 0.3.0๐Ÿ˜•):

nuxt.config.js

  buildModules: [
    ['@nuxtjs/svg-sprite', {
      input: '~/assets/svg/',
      output: '~/assets/svg/generated/'
    }]
  ],

Insert title and desc tags

Want to insert title and desc tags.

See follow the example.

Set title and desc tags to svg element.

<svg-icon
  name="sample"
  title="Title"
  desc="Description"
/>

After built,

<svg xmlns="http://www.w3.org/2000/svg">
  <title>Title</title>
  <desc>Description</desc>
  <use xlink:href="/_nuxt/assets/sprite/gen/icons.svg#i-sample"></use>
</svg>

Do not modify app.html file if no changes occur

app.html is modified by every run of nuxt command even though no icons are changed in the resources. This is very irritating since file is not a gitignore list and it always needs to be reverted before the commit

Different SVGO options for each sprite

Hello, thanks for the awesome module!
I was wondering if there is a possibility to use different SVGO options depending on the spritesheet that is generated. I would like to use the default one for monochromatic icons (/icons) where I overwrite colors with currentColor (convertColors.params.currentColor = true) and one for colored icons (/icons/colored) where it doesn't overwrite them.

How to correctly reference sprite

Hello,

I installed this library and tried to do something like the below code, but, referencing sprite in assets folder, does't work for me when v-binding to :xlink:href. Since it is a nuxt project what I did was to set the output to the static folder. v-binding to static folder sprite works fine, but I'm not sure if it is the best way to do this.

svgSprite: { input: '~/assets/images/icons', output: '~/static/sprite' },

`

<svg class="icon__svg">
  <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="~/assets/sprite/gen/icons.svg#i-bold"></use>
</svg>    

<!-- v-binding (to assets folder) - Doesn't work --> 

<svg class="icon__svg">
  <use xmlns:xlink="http://www.w3.org/1999/xlink" :xlink:href="'~/assets/sprite/gen/icons.svg#i-bold'"></use>
</svg>

<!-- Binding (to static folder) - Works fine --> 

<svg class="icon__svg">
  <use xmlns:xlink="http://www.w3.org/1999/xlink" :xlink:href="'/sprite/icons.svg#i-add-col-after'"></use>
</svg>

`

What is the correct way to reference the sprite in assets folder?

How to custom layout ?

Hello,

The default layout is use for render the page, it is possible to change it into the config ?
I would like use a new layout for show the generated icons.

Thanks

UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '.../.nuxt/nuxt-svg-sprite-icons-list.vue'

Hi there,

I'm using SSR mode with express server and I got below error:

(node:25166) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '.../.nuxt/nuxt-svg-sprite-icons-list.vue' 

It can't generate the template correctly in the dev mode, but production mode works really well.

the build process of below code:

  if (this.nuxt.options.dev) {
    this.addTemplate({
      src: path.resolve(__dirname, 'pages', 'icons-list.vue'),
      fileName: 'nuxt-svg-sprite-icons-list.vue',
      options
    })
    // register page
    this.nuxt.hook('build:extendRoutes', (routes) => {
      routes.push({
        name: 'icons-list',
        path: options.iconsPath,
        component: path.resolve(this.nuxt.options.buildDir, 'nuxt-svg-sprite-icons-list.vue')
      })
    })
  }

should change like this:

if (this.nuxt.options.dev) {
    this.addTemplate({
      src: path.resolve(__dirname, 'pages', 'icons-list.vue'),
      fileName: 'nuxt-svg-sprite-icons-list.vue',
      options
    })
    // register page
    this.extendRoutes((routes) => {
      routes.push({
        name: 'icons-list',
        path: options.iconsPath,
        component: path.resolve(this.nuxt.options.buildDir, 'nuxt-svg-sprite-icons-list.vue')
      })
    })
  }

Incompatible with SSR in aws-lambda

Module is making FS write calls during load. nuxt.render is failing in Lambda function as it's a read-only environment. Can't we generate sprite and .gitignore files during build phase only?

Svg files have black spots instead of color

Hello, thank you to both Nuxt and the creators of the module for providing it as a service for us Vue - Nuxt developers.

I wanted to test it before I start implementing it in personal projects. I used free SVG icons and illustrations found through the sites drawkit (which has some wonderful ones under MIT license) and flaticon.

You can see from my testing repository that some of them show black spots instead of their actual color and others (the dog and the hand) look as they should. Is this a problem of the svg files themselves, the svg-sprite-module or have I done something wrong?

I did some farther searching and found that such problems with black spots on svgs occurred in more Github repositories like ( 1, 2 ) so I guess it might be a generic svg problem?

You can find my testing repo at nuxt-svg-test

Steps to view the problem :

1). Clone the repo
2). Run npm install
3). Run npm run lint -- --fix
4). Run npm run dev

I installed the module, created the 2 needed folders in assets and imported the svg files. Then, I used them in the index.vue page as you can see after running the project.

Hopefully it isn't something complicating

Thank you for your time

Allow injection of SVG sprite per page

It's not always efficient to inject whole SVG sprite at body level. Sometimes we need certain icons only on certain pages so it would be better if there was an opportunity to split icons into multiple sprites and include them at different pages or layouts

Remove unused svg items

It would be interesting if the generated sprite only included the icons that are actually beeing used.

Now everything you add to the folder gets automatically added to the sprite.

Plugin not found .../.nuxt/nuxt-svg-sprite.js

After installing svg-sprite and launching npm run dev, i got next error:

Plugin not found: Project_folder\.nuxt\nuxt-svg-sprite.js 
  at Promise.all.plugins.map (node_modules\@nuxt\builder\dist\builder.js:6031:15)

There is my nuxt config:

module.exports = {
  // Load modules
  modules: ['@nuxtjs/svg-sprite'],

  // Connect global css rules
  css: [
    '@/assets/scss/basic.scss'
  ],

  // Headers
  head: {
    title: 'projectname',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: 'project description' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  
  // Progress bar
  loading: { color: '#3B8070' },

  // Server config
  server: {
    port: 3000,
    host: '0.0.0.0'
  },

  // Build config
  build: {

    //cache: true,
    //parallel: true,
    
    // Run ESLint on save
    extend (config, { isDev, isClient }) {
      if (isDev && isClient) {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/
        })
      }
    }
  }
}

What's wrong here? File nuxt-svg-sprite.js exist in .nuxt, and nuxt-svg-sprite-icons-list.vue also created after npm run dev

How to use it with svg file with symbols ?

I have svg file with symbols. In the final assembly, am I getting an empty tag?

<symbol id="i-test" xmlns="http://www.w3.org/2000/svg" style="position:absolute" viewBox="0 0 0 0"/>

SVG 2 compatibilty

Since SVG 2, the xlink:href attribute is deprecated in favor of simply href. See xlink:href page for more information. However, xlink:href can still be required in practice for cross-browser compatibility (see the compatibility table below). MDN

defaultSprite under nuxt build

I found it must name the input dir to icons, and nuxt build (spa, not ssr) will generate a file named icons.svg.
if the dir named svg, it will get a svg.svg file.

but in dev mode, nuxt can translate dir named svg to file icons.svg.

CA0E5E73-3CCA-4b9e-9CFD-D09C8ED74A01

[Feature request] Expose an array with icons data for custom list generation

Although there is a separate page that is generated for icons, there is no good way of controlling it's behavior, like adding layout, modify the look, etc.
There should be a way to generate such page from scratch based on the icons data. Such data object should be added to Vue instance after icons are generated and be accessible via this, something like this.$svgSptite
Such list can also be used for other creative purposes like generating icons sets on different pages, etc.

This module doesn't work when using Typescript Nuxt-ts

FATAL Cannot read property 'hasAttr' of null 12:40:04

at _findById (node_modules/@nuxtjs/svg-sprite/lib/plugins/inlineDefs.js:200:15)
at Proxy.exports.fn (node_modules/@nuxtjs/svg-sprite/lib/plugins/inlineDefs.js:60:15)
at node_modules/svgo/lib/svgo/plugins.js:95:27
at Array.forEach ()
at full (node_modules/svgo/lib/svgo/plugins.js:93:13)
at node_modules/svgo/lib/svgo/plugins.js:25:24
at Array.forEach ()
at module.exports (node_modules/svgo/lib/svgo/plugins.js:15:13)
at node_modules/svgo/lib/svgo.js:70:17
at SAXParser.sax.onend (node_modules/svgo/lib/svgo/svg2js.js:169:13)
at emit (node_modules/sax/lib/sax.js:624:35)
at end (node_modules/sax/lib/sax.js:667:5)
at SAXParser.write (node_modules/sax/lib/sax.js:975:14)
at SAXParser.close (node_modules/sax/lib/sax.js:157:38)
at module.exports (node_modules/svgo/lib/svgo/svg2js.js:182:28)
at SVGO._optimizeOnce (node_modules/svgo/lib/svgo.js:64:5)

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ โ”‚
โ”‚ โœ– Nuxt Fatal Error โ”‚
โ”‚ โ”‚
โ”‚ TypeError: Cannot read property 'hasAttr' of null โ”‚
โ”‚ โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Seems to work on the demo and I replicated the same setup inside our project with the same error, removing the plugin removes the errors.

Not supported in Node v10? import path from 'path'

So I have an error

@nuxtjs\svg-sprite\lib\module.js:1
  (function (exports, require, module, __filename, __dirname) { import path from 'path'
                                                                       ^^^^
  SyntaxError: Unexpected identifier

AFAIK es6 imports are not enabled by default, are we supposed to run with experimental features flag ? I can't use this sprite generator, my Nuxt app renders with Error Cannot GET /

Omit default namespace when copying icon name of the _icons page

Right now when I click on the icon name and copy it to clipboard - I get default namespace also copied so the result is: icons/icon-name, which is a bit redundant since icon-name will work just fine cos it is located in the root folder anyway so it would be great if namespace was added only for internal folders

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.