Vue-svg-loader: Add option for string loading

Created on 16 Jan 2019  路  2Comments  路  Source: visualfanatic/vue-svg-loader

As we have ?external it would be nice to have ?raw and get svg loaded as string?
Or is this possible already?

Most helpful comment

in case if anyone is interested. there is also a way to inline svg and convert it to base64 so you dont need extra request when adding image to css.

config:

.oneOf('base64')
      .resourceQuery(/base64/)
      .use('url-loader')
      .loader('url-loader')
      .end()
      .end()

css:

    .icon-img {
      background-image: url('~@/assets/error.svg?base64');
    }

All 2 comments

Yes, it's currently possible by using raw-loader, you need to modify your webpack config like so:

module.exports = {
  module: {
    rules: [
      {
        test: /\.svg$/,
        oneOf: [
          {
            resourceQuery: /raw/,
            loader: 'raw-loader',
          },
          {
            loader: 'vue-svg-loader',
          },
        ],
      },
    ],
  },
};

in case if anyone is interested. there is also a way to inline svg and convert it to base64 so you dont need extra request when adding image to css.

config:

.oneOf('base64')
      .resourceQuery(/base64/)
      .use('url-loader')
      .loader('url-loader')
      .end()
      .end()

css:

    .icon-img {
      background-image: url('~@/assets/error.svg?base64');
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

simon04 picture simon04  路  5Comments

sashakaralchuk picture sashakaralchuk  路  6Comments

edarioq picture edarioq  路  6Comments

Peppe87 picture Peppe87  路  4Comments

dsbert picture dsbert  路  6Comments