{"_id":"@chaoyang805/svg-sprite-webpack-plugin","_rev":"1-43cd352223d0d29fd7774abb687744c2","name":"@chaoyang805/svg-sprite-webpack-plugin","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.1":{"name":"@chaoyang805/svg-sprite-webpack-plugin","version":"0.1.1","main":"lib/cjs.js","author":{"name":"chaoyang805","email":"zhangchaoyang805@gmail.com"},"repository":{"type":"git","url":"https://github.com/chaoyang805/svg-sprite-webpack-plugin.git"},"keywords":["webpack","plugin","loader","icon","svg","sprite"],"license":"MIT","scripts":{"clean":"rimraf lib","build":"babel -x .ts src --out-dir lib --copy-files","lint":"eslint 'src/**/*.{js,ts}'"},"types":"types/index.d.ts","peerDependencies":{"webpack":"^4.44.0"},"dependencies":{"core-js":"^3.6.5","loader-utils":"^2.0.0","schema-utils":"^3.0.0","svgo":"^1.3.2"},"devDependencies":{"@babel/cli":"^7.12.10","@babel/core":"^7.12.10","@babel/plugin-proposal-class-properties":"^7.12.1","@babel/plugin-transform-typescript":"^7.12.1","@babel/preset-env":"^7.12.10","@babel/preset-typescript":"^7.12.1","@typescript-eslint/eslint-plugin":"^4.13.0","@typescript-eslint/parser":"^4.13.0","eslint":"^7.18.0","eslint-config-prettier":"^7.1.0","eslint-config-standard":"^16.0.2","eslint-plugin-import":"^2.22.1","eslint-plugin-node":"^11.1.0","eslint-plugin-prettier":"^3.3.1","eslint-plugin-promise":"^4.2.1","prettier":"^2.2.1","rimraf":"^3.0.2","typescript":"^4.0.5"},"description":"A webpack plugin and loader for combining individual svg icons into a single svg sprite file, just like css image sprite.","licenseText":"MIT License\n\nCopyright (c) 2021 chaoyang805\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@chaoyang805/svg-sprite-webpack-plugin@0.1.1","dist":{"shasum":"0614b269df4d6fac28dcd72ecffbbd315a460ea6","integrity":"sha512-w0cP2/kvbDQSmfyw6yYKzW3Kbgsxnu/n2QeUtG3VQrwHkTMsnvNF98oaS2CpSB9RRoxAqarbuIdGe6rBhLfKvQ==","tarball":"https://registry.npmjs.org/@chaoyang805/svg-sprite-webpack-plugin/-/svg-sprite-webpack-plugin-0.1.1.tgz","fileCount":11,"unpackedSize":17342,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgBS9NCRA9TVsSAnZWagAA+AQP/AjdrZ3pzjSWi56udABs\n55jbduytshiETDnSTqEmRsM4jttPHowCmMCG+AmaCfTl1ZyKW8t+O6EtVyav\nc9SQwJ8pe7PSQ71upqOv6dnUXATmuuMqK578whUBpZPoIfDvPkRJdnzw6H9C\nizmfuSZzFy1+/sS9bgvceClBxFWrDXtSMmOdn5RN+lYYZMMJBMRKi0twwHS4\n4uxcCFqUknVNn5FMEqz4pIO1v7/78LcA3EDND4/KI+bqhHSMmYfJB9OyB0wF\naddZA+l202d75RsX4aAOImV/XrJeVRe5AuRdB8RgNXiqybS6urqUWlHCRmnN\nRgrT0mr2WWCEQ6B6vE4OTKjuUi8lJUJNiy9FUIZ9KtfQQYc8ONvgnXDQ04Vj\nhRuYuBf9CypNQLKWhUtTtVos86cWx63N/Wu9sa3FEom0vuySGQynCDrqDFMw\n4c7f8DsmI4JU02Y8gnBM3/aqEqBkMRPYv97UudU3X6tN3cAT14v4h5++iCpy\nFApxbi6CZABYQ8r/HyufyB6CI9w4lrQ7nsn/m71cHtw3Bx/lvO4G7wKncxGw\nzQYOLf+OliVYRuwh/g8il07tImyuh83rVMs0Kken/tDM3hGygd95gZpVu5E8\nB1LhCSw/WOU6lVplI88TAy4Km9OdopMDCcsJsY4bmL6gYHxhAvPDsZ53+WY+\nvwhq\r\n=Vip/\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC16lD6UxmLjqJeAy8sajyWJkPC20p22K4eViIwmNJTigIgKuXlZCPO53KWwbi1M6tTN07mlE1ewLdwooc9ODdTpMw="}]},"_npmUser":{"name":"chaoyang805","email":"zhangchaoyang805@gmail.com"},"directories":{},"maintainers":[{"name":"chaoyang805","email":"zhangchaoyang805@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/svg-sprite-webpack-plugin_0.1.1_1610952524798_0.8495035485957103"},"_hasShrinkwrap":false}},"time":{"created":"2021-01-18T06:48:44.761Z","0.1.1":"2021-01-18T06:48:44.957Z","modified":"2022-04-04T22:31:24.453Z"},"maintainers":[{"name":"chaoyang805","email":"zhangchaoyang805@gmail.com"}],"description":"A webpack plugin and loader for combining individual svg icons into a single svg sprite file, just like css image sprite.","keywords":["webpack","plugin","loader","icon","svg","sprite"],"repository":{"type":"git","url":"https://github.com/chaoyang805/svg-sprite-webpack-plugin.git"},"author":{"name":"chaoyang805","email":"zhangchaoyang805@gmail.com"},"license":"MIT","readme":"# svg-sprite-webpack-plugin\n\nA webpack plugin and loader for combining individual svg icons into a single svg sprite file, just like css image sprite.\n\n## Installation\n\n`npm install --save-dev @chaoyang805/svg-sprite-webpack-plugin`\n\n## Fundamental\n\nThis tool loads your svg icons into a single svg file containing several `<symbol>` nodes. Then you can refrence this svg icons via attribute `xlink:href=\"/img/icons.svg#icon-avatar\"` in `<use>` node of the `<svg></svg>` tag. For example, assume you have these icons:\n\n```xml\n<!-- icon-avatar.svg -->\n<svg width=\"14\" height=\"16\" viewBox=\"0 0 14 16\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M1.3388 10.7239C2.03978 9.99693 2.99645 9.58325 4 9.58325H10C11.0035 9.58325 11.9602 9.99693 12.6612 10.7239C13.3613 11.4499 13.75 12.429 13.75 13.4444V14.9999C13.75 15.4141 13.4142 15.7499 13 15.7499C12.5858 15.7499 12.25 15.4141 12.25 14.9999V13.4444C12.25 12.8095 12.0066 12.206 11.5814 11.7651C11.1572 11.3251 10.5878 11.0833 10 11.0833H4C3.41225 11.0833 2.8428 11.3251 2.41856 11.7651C1.99343 12.206 1.75 12.8095 1.75 13.4444V14.9999C1.75 15.4141 1.41421 15.7499 1 15.7499C0.585786 15.7499 0.25 15.4141 0.25 14.9999V13.4444C0.25 12.429 0.638707 11.4499 1.3388 10.7239Z\" fill=\"white\"/>\n<path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M7 1.75C5.78283 1.75 4.75 2.78116 4.75 4.11111C4.75 5.44106 5.78283 6.47222 7 6.47222C8.21717 6.47222 9.25 5.44106 9.25 4.11111C9.25 2.78116 8.21717 1.75 7 1.75ZM3.25 4.11111C3.25 2.00462 4.90346 0.25 7 0.25C9.09654 0.25 10.75 2.00462 10.75 4.11111C10.75 6.2176 9.09654 7.97222 7 7.97222C4.90346 7.97222 3.25 6.2176 3.25 4.11111Z\" fill=\"white\"/>\n</svg>\n```\n\n```xml\n<!-- icon-delete.svg -->\n<svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M0.5 3.40002C0.5 3.12388 0.723858 2.90002 1 2.90002H13C13.2761 2.90002 13.5 3.12388 13.5 3.40002C13.5 3.67617 13.2761 3.90002 13 3.90002H1C0.723858 3.90002 0.5 3.67617 0.5 3.40002Z\" fill=\"#EF4545\"/>\n<path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M5.66659 1.5C5.42956 1.5 5.21148 1.58522 5.05826 1.72312C4.90678 1.85945 4.83325 2.03237 4.83325 2.2V2.9H9.16658V2.2C9.16658 2.03237 9.09306 1.85945 8.94158 1.72312C8.78836 1.58522 8.57027 1.5 8.33325 1.5H5.66659ZM10.1666 2.9V2.2C10.1666 1.73111 9.95916 1.29358 9.61054 0.979825C9.26366 0.667634 8.80347 0.5 8.33325 0.5H5.66658C5.19636 0.5 4.73617 0.667634 4.38929 0.979825C4.04068 1.29358 3.83325 1.73111 3.83325 2.2V2.9H2.33325C2.05711 2.9 1.83325 3.12386 1.83325 3.4V11.8C1.83325 12.2689 2.04068 12.7064 2.38929 13.0202C2.73617 13.3324 3.19636 13.5 3.66659 13.5H10.3333C10.8035 13.5 11.2637 13.3324 11.6105 13.0202C11.9592 12.7064 12.1666 12.2689 12.1666 11.8V3.4C12.1666 3.12386 11.9427 2.9 11.6666 2.9H10.1666ZM2.83325 3.9V11.8C2.83325 11.9676 2.90678 12.1405 3.05826 12.2769C3.21148 12.4148 3.42956 12.5 3.66659 12.5H10.3333C10.5703 12.5 10.7884 12.4148 10.9416 12.2769C11.0931 12.1405 11.1666 11.9676 11.1666 11.8V3.9H2.83325Z\" fill=\"#EF4545\"/>\n<path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M5.6665 5.90015C5.94265 5.90015 6.1665 6.124 6.1665 6.40015V10.0001C6.1665 10.2763 5.94265 10.5001 5.6665 10.5001C5.39036 10.5001 5.1665 10.2763 5.1665 10.0001V6.40015C5.1665 6.124 5.39036 5.90015 5.6665 5.90015Z\" fill=\"#EF4545\"/>\n<path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M8.33325 5.90015C8.60939 5.90015 8.83325 6.124 8.83325 6.40015V10.0001C8.83325 10.2763 8.60939 10.5001 8.33325 10.5001C8.05711 10.5001 7.83325 10.2763 7.83325 10.0001V6.40015C7.83325 6.124 8.05711 5.90015 8.33325 5.90015Z\" fill=\"#EF4545\"/>\n</svg>\n```\n\nafter use this plugin and loader in you webpack project, these svg icons will be combined to a new svg file like below:\n\n```xml\n<svg width=\"0\" height=\"0\" style=\"display: none;\">\n  <symbol id=\"icon-avatar-2ce6a7dd\">\n    <!-- your svg path data... -->\n  </symbol>\n  <symbol id=\"icon-delete-3ab0bd92\">\n    <!-- your svg path data... -->\n  </symbol>\n  <!-- more symbol nodes... -->\n</svg>\n```\n\nyou can use these icons in html\n\n```html\n<svg>\n  <use xlink:href=\"img/icons.svg#icon-avatar-2ce6a7dd\"></use>\n</svg>\n```\n\nYou need first import it in you js code, of course.\n\n```javascript\nimport iconAvatar from '@/assets/icon-avatar.svg' // iconAvatar = 'img/icons.svg#icon-avatar-2ce6a7dd'\n```\n\n## Usage\n\n### config webpack\n\n```javascript\n// webpack.config.js\nconst SvgSpritePlugin = require('@chaoyang805/svg-sprite-webpack-plugin');\n\nmodule.exports = {\n  ...\n  module: {\n    rules: [\n      ...\n      // add svg-sprite-loader here before any other svg loaders\n      {\n        test: /\\.svg$/,\n        use: SvgSpritePlugin.loader,\n      },\n      ...\n    ],\n  },\n  plugins: [\n    new SvgSpritePlugin({\n      // filename represents the output svg file name. it only supports static name for now\n      filename: 'img/icons.svg',\n    }),\n    ...\n  ]\n  ...\n}\n```\n\nIf you are using vue-cli，create a vue.config.js file and add code:\n\n```javascript\n// vue.config.js\nconst path = require('path')\nconst SvgSpritePlugin = require('@chaoyang805/svg-sprite-webpack-plugin');\nmodule.exports = {\n  ...,\n  chainWebpack(config) {\n    config.plugin('svg-sprite').use(SvgSpritePlugin, [{ filename: 'img/icons.svg' }])\n    config.module.rule('svg')\n      .test(/\\.svg$/i)\n        .use('svg-sprite')\n        .before('file-loader')\n        .loader(SvgSpritePlugin.loader)\n      .end()\n  },\n  ...\n}\n```\n\n### Use in Vue component\n\n```vue\n<template>\n<svg class=\"icon icon-avatar\">\n  <use :xlink:href=\"iconAvatar\"></use>\n</svg>\n</template>\n<script>\n\timport iconAvatar from '@/assets/icon-avatar.svg'\n  export default {\n    name: 'icon-avatar',\n    data() {\n    \treturn {\n      \ticonAvatar  \n      };\n    },\n  }\n</script>\n<style lang=\"scss\" scoped>\n  .icon {\n    fill: currentColor;\n    width: 1em;\n    height: 1em;\n    vertical-align: middle;\n  }\n  .icon-avatar {\n    color: grey;\n    font-size: 18px;\n  }\n</style>\n```\n\n### Use in plain javascript\n\nfirst import icon in you javascript code\n\n```javascript\nimport iconAvatar from '@/assets/icon-avatar.svg' // iconAvatar = 'img/icons.svg#icon-avatar-2ce6a7dd'\n\n// do not forget svg tag is created by createElementNS method.\nconst svgIcon = document.createElementNS('http://www.w3.org/2000/svg', 'svg');\nconst use = document.createElementNS('http://www.w3.org/2000/svg', 'use');\nuse.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', iconAvatar);\n\nsvgIcon.appendChild(use);\ndocument.body.appendChild(svgIcon);\n```\n","readmeFilename":"README.md"}