0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

vue-loaderでsourceのsrcsetで指定したファイルも自動でrequireする

Last updated at Posted at 2017-03-08

vue-loaderではデフォルトでsourceタグのsrcset属性で指定したファイルを自動でrequireしてくれない

<template>
  <picture>
    <source media="(min-width: 768px)" srcset="~@/assets/large.jpg" />
    <img src="~@/assets/home/default.jpg">
  </picture>
<template>

vue-loaderのoptionsで以下のようにrequireするタグの属性を追加できる
https://vue-loader.vuejs.org/en/options.html

{
  test: /\.vue$/,
  loader: 'vue-loader',
  options: {
    transformToRequire: {
      source: 'srcset', // keyにタグ名、値に属性名、配列で複数渡せる
    }
  }
}

imgのsrcset属性は値にパス以外も入ってくるので、このやり方ではたぶんできません。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?