{"name":"svg-url-loader","version":"8.1.0","description":"Converts SVG file to utf-8 encoded data-uri string","main":"./index.js","scripts":{"format":"prettier --write '**/*.{ts,tsx,js,jsx,css,md,yml}'","test":"jest --runInBand --coverage","test-watch":"jest --runInBand --watch"},"dependencies":{"file-loader":"~6.2.0"},"peerDependencies":{"webpack":"^5.0.0"},"repository":{"type":"git","url":"git+https://github.com/bhovhannes/svg-url-loader.git"},"keywords":["data-uri","encoding","loader","svg","url-loader","utf8","webpack"],"author":{"name":"Hovhannes Babayan"},"license":"MIT","bugs":{"url":"https://github.com/bhovhannes/svg-url-loader/issues"},"homepage":"https://github.com/bhovhannes/svg-url-loader#readme","devDependencies":{"@bhovhannes/shared-config":"0.0.1","@evilmartians/lefthook":"2.1.9","@jest/globals":"30.4.1","css-loader":"5.2.7","jest":"30.4.2","less":"4.6.4","less-loader":"12.3.3","prettier":"3.8.4","sass":"1.101.0","sass-loader":"16.0.8","webpack":"5.107.2"},"engines":{"node":">=14"},"gitHead":"febbba02b43288733a6ca727d9036dd3f7730c28","_id":"svg-url-loader@8.1.0","_nodeVersion":"26.1.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-8Mf5g0R44VSiTQnSXT6qCSHwCO3VwZAOcm+o0FB80wGGeZNDzKBPKc8gtfIbSfNPmnE8SHv/+e49vO2NVHEmKA==","shasum":"d947f70ee0225a755b080eb489eb522bdec4378f","tarball":"http://registry-npm.ywwl.com/svg-url-loader/download/svg-url-loader-8.1.0.tgz","fileCount":5,"unpackedSize":11372,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCT8cOEc6+iMGn3cUl2MC4blqmC4GJcBSM0+npzQWtwggIhALbpsi+riItb7wofKQihd+vE0N2OfV+VenX0NUil1ijl"}],"size":4629,"noattachment":false,"key":"/svg-url-loader/-/svg-url-loader-8.1.0.tgz"},"_npmUser":{"name":"bhovhannes","email":"bhovhannes@gmail.com"},"directories":{},"maintainers":[{"name":"bhovhannes","email":"bhovhannes@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/svg-url-loader_8.1.0_1781382777829_0.6186644035237545"},"_hasShrinkwrap":false,"readme":"# svg-url-loader\n\n[![NPM version][npm-version-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-url] [![codecov][codecov-image]][codecov-url] [![MIT License][license-image]][license-url]\n\nA webpack loader which loads SVG file as utf-8 encoded DataUrl string.\n\nExisting [`url-loader`](https://github.com/webpack-contrib/url-loader) always does Base64 encoding for data-uri. As SVG content is a human-readable xml string, using base64 encoding is not mandatory. Instead, one may only escape [unsafe characters](http://www.ietf.org/rfc/rfc1738.txt) and replace `\"` with `'` as described [in this article](http://codepen.io/Tigt/post/optimizing-svgs-in-data-uris).\n\nThere are some benefits for choosing utf-8 encoding over base64.\n\n1. Resulting string is shorter (can be ~2 times shorter for 2K-sized icons);\n2. Resulting string will be compressed better when using gzip compression;\n3. Browser parses utf-8 encoded string faster than its base64 equivalent.\n\n## Supported parameters\n\nParameters can be passed both in an url or from webpack config file. See [Loaders](https://webpack.js.org/concepts/loaders/) section in webpack documentation for more details.\n\nPassing parameters using `resourceQuery` is also supported:\n\n```css\n.selector {\n  background-image: url(../assets/foo.svg?encoding=base64);\n}\n```\n\nThe loader supports the following parameters:\n\n### `limit`\n\nIf given, loader will not encode the source file if its content is greater than this limit.\nDefaults to no limit.\nIf the file is greater than the limit the [`file-loader`](https://github.com/webpack-contrib/file-loader) is used, receiving all query parameters set for svg-url-loader.\n\n```javascript\nrequire(\"svg-url-loader?limit=1024!./file.svg\");\n// => DataUrl if \"file.png\" is smaller that 1kb\n\nrequire(\"svg-url-loader?prefix=img/!./file.svg\");\n// => Parameters for the file-loader are valid too\n//    They are passed to the file-loader if used.\n```\n\n### `stripdeclarations`\n\nThis option is true by default. **It will be removed in the next major release.**  \nSee [this issue](https://github.com/bhovhannes/svg-url-loader/issues/104#issuecomment-348377933) for more context about this decision.\n\nIf given will tell the loader to strip out any XML declaration, e.g. `<?xml version=\"1.0\" encoding=\"UTF-8\"?>` at the beginning of imported SVGs.\nInternet Explorer (tested in Edge 14) cannot handle XML declarations in CSS data URLs (`content: url(\"data:image/svg...\")`).\n\n```javascript\nrequire(\"svg-url-loader?stripdeclarations!./file.svg\");\n```\n\n### `iesafe`\n\nThis option tells loader to fall back to the file-loader if the file contains a style-element and the encoded size is above 4kB no matter the `limit` specified.\n\nThis option was introduced because Internet Explorer (including IE11) stops parsing style-elements in SVG data-URIs longer than 4kB. This results in black fill-color for all styled shapes.\n\nYou can either specify `iesafe` option in the query:\n\n```javascript\n// apply `iesafe` option only for 'foo.svg'\nrequire(\"svg-url-loader?iesafe!./foo.svg\");\n```\n\nOr, you can set this option globally in you webpack config:\n\n```javascript\nmodule.exports = {\n  //...\n  module: {\n    rules: [\n      {\n        test: /\\.svg/,\n        use: {\n          loader: \"svg-url-loader\",\n          options: {\n            // make all svg images to work in IE\n            iesafe: true,\n          },\n        },\n      },\n    ],\n  },\n  //...\n};\n```\n\n### `stripSpaces`\n\nThis option is `true` by default.\n\nIf set to `false`, the loader will not aggressively minify whitespaces (except newlines and multiple spaces). This is useful when you need to preserve significant whitespace inside SVG `<text>` elements.\n\nYou can specify the `stripSpaces` option in the query:\n\n```javascript\nrequire(\"svg-url-loader?stripSpaces=false!./file.svg\");\n```\n\nOr set it globally in your webpack config:\n\n```javascript\nmodule.exports = {\n  //...\n  module: {\n    rules: [\n      {\n        test: /\\.svg/,\n        use: {\n          loader: \"svg-url-loader\",\n          options: {\n            stripSpaces: false,\n          },\n        },\n      },\n    ],\n  },\n  //...\n};\n```\n\n### `encoding`\n\nThis option controls which encoding to use when constructing a data-URI for an SVG. When set to a non-\"none\" value, loader does not apply quotes to the resulting data-URI.\n\nPossible values are \"base64\" and \"none\". Defaults to \"none\".\n\nNormally, setting `encoding` option to `base64` _should not_ be required, as using base64 encoding defeats the original purpose of this loader - embed svg with minimal size overhead. However, because of incompatibility with some tools, we support this mode, too.\n\nYou can either specify `base64` option in the query:\n\n```javascript\n// apply `base64` option only for 'foo.svg'\nrequire(\"svg-url-loader?encoding=base64!./foo.svg\");\n```\n\nOr, you can set this option globally in you webpack config:\n\n```javascript\nmodule.exports = {\n  //...\n  module: {\n    rules: [\n      {\n        test: /\\.svg/,\n        use: {\n          loader: \"svg-url-loader\",\n          options: {\n            // make loader to behave like url-loader, for all svg files\n            encoding: \"base64\",\n          },\n        },\n      },\n    ],\n  },\n  //...\n};\n```\n\n## Usage\n\n[Documentation: Loaders](https://webpack.js.org/concepts/loaders/)\n\n### In JS:\n\n```javascript\nrequire(\"svg-url-loader!./file.svg\");\n// => DataUrl for file.svg\n```\n\n### In CSS (with webpack.config.js below):\n\n```css\n.icon {\n  background: url(\"../images/file.svg\");\n}\n```\n\n```javascript\nmodule.exports = {\n  //...\n  module: {\n    rules: [\n      {\n        test: /\\.svg/,\n        use: {\n          loader: \"svg-url-loader\",\n          options: {},\n        },\n      },\n    ],\n  },\n  //...\n};\n```\n\n## Benefits of using data-uri\n\n1. Browser won't make an extra http call to download the image\n2. Some folks [mentioned](https://github.com/bhovhannes/svg-url-loader/issues/341) that even if image is in browser cache images with data url appear on screen faster.\n\n## License\n\nMIT (http://www.opensource.org/licenses/mit-license.php)\n\n[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square\n[license-url]: LICENSE\n[npm-url]: https://www.npmjs.org/package/svg-url-loader\n[npm-version-image]: https://img.shields.io/npm/v/svg-url-loader.svg?style=flat-square\n[npm-downloads-image]: https://img.shields.io/npm/dm/svg-url-loader.svg?style=flat-square\n[codecov-url]: https://codecov.io/gh/bhovhannes/svg-url-loader\n[codecov-image]: https://codecov.io/gh/bhovhannes/svg-url-loader/branch/master/graph/badge.svg?token=iJvUUKrgzB\n","publish_time":1781382778021,"_cnpm_publish_time":1781382778021,"dist-tags":{"latest":"8.1.0"}}