Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 3 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # @svgr/webpack
  2. [![Build Status][build-badge]][build]
  3. [![version][version-badge]][package]
  4. [![MIT License][license-badge]][license]
  5. Webpack loader for SVGR.
  6. ```
  7. npm install @svgr/webpack
  8. ```
  9. ## Usage
  10. In your `webpack.config.js`:
  11. ```js
  12. {
  13. test: /\.svg$/,
  14. use: ['@svgr/webpack'],
  15. }
  16. ```
  17. In your code:
  18. ```js
  19. import Star from './star.svg'
  20. const App = () => (
  21. <div>
  22. <Star />
  23. </div>
  24. )
  25. ```
  26. ### Passing options
  27. ```js
  28. {
  29. test: /\.svg$/,
  30. use: [
  31. {
  32. loader: '@svgr/webpack',
  33. options: {
  34. native: true,
  35. },
  36. },
  37. ],
  38. }
  39. ```
  40. ### Using with `url-loader` or `file-loader`
  41. It is possible to use it with [`url-loader`](https://github.com/webpack-contrib/url-loader) or [`file-loader`](https://github.com/webpack-contrib/file-loader).
  42. In your `webpack.config.js`:
  43. ```js
  44. {
  45. test: /\.svg$/,
  46. use: ['@svgr/webpack', 'url-loader'],
  47. }
  48. ```
  49. In your code:
  50. ```js
  51. import starUrl, { ReactComponent as Star } from './star.svg'
  52. const App = () => (
  53. <div>
  54. <img src={starUrl} alt="star" />
  55. <Star />
  56. </div>
  57. )
  58. ```
  59. ### Use your own Babel configuration
  60. By default, `@svgr/webpack` includes a `babel-loader` with [optimized configuration](https://github.com/smooth-code/svgr/blob/master/packages/webpack/src/index.js). In some case you may want to apply a custom one (if you are using Preact for an example). You can turn off Babel transformation by specifying `babel: false` in options.
  61. ```js
  62. // Example using preact
  63. {
  64. test: /\.svg$/,
  65. use: [
  66. {
  67. loader: 'babel-loader',
  68. options: {
  69. presets: ['preact', 'env'],
  70. },
  71. },
  72. {
  73. loader: '@svgr/webpack',
  74. options: { babel: false },
  75. }
  76. ],
  77. }
  78. ```
  79. ### Handle SVG in CSS, Sass or Less
  80. It is possible to detect the module that requires your SVG using [`Rule.issuer`](https://webpack.js.org/configuration/module/#rule-issuer) in Webpack. Using it you can specify two different configurations for JavaScript and the rest of your files.
  81. ```js
  82. {
  83. {
  84. test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
  85. issuer: {
  86. test: /\.jsx?$/
  87. },
  88. use: ['babel-loader', '@svgr/webpack', 'url-loader']
  89. },
  90. {
  91. test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
  92. loader: 'url-loader'
  93. },
  94. }
  95. ```
  96. ## License
  97. MIT
  98. [build-badge]: https://img.shields.io/travis/smooth-code/svgr.svg?style=flat-square
  99. [build]: https://travis-ci.org/smooth-code/svgr
  100. [version-badge]: https://img.shields.io/npm/v/@svgr/webpack.svg?style=flat-square
  101. [package]: https://www.npmjs.com/package/@svgr/webpack
  102. [license-badge]: https://img.shields.io/npm/l/@svgr/webpack.svg?style=flat-square
  103. [license]: https://github.com/smooth-code/svgr/blob/master/LICENSE