supports uri fragment in static style transformed require
resolved vuejs/vue-loader#646
I would rather extend implementation of rewrite method to handle asset URLs in inline style.
In fact, Node.attrs doesn't contain style attribute, or should we modify the compiler?

If we transform, asset URLs in static style attribute then behaviour of bounded style attribute should be same, which can be little difficult to achieve.
We don't transform bounded style, we can require resources explicitly.
In these cases:
<div :style="`background: url('/some/image/path/${filename}.png')`">
<!-- developers rely on "/some/image/path/" -->
<div :style="`background: ${backgroundLink}`">
<!-- this.backgroundLink = require('path/to/image') -->
<div :style="`${backgroundStyle}`">
<!-- this.backgroundStyle = `background: url${require('path/to/image')}` -->
Yes, staticStyle will be an object in compiled render function.
I tested in vue-loader's example, it works just fine.
Here is my test steps:
- ~~Hard code default transformOption, add
{ '*': 'style'}~~ Add following options tovue-loaderinwebpack.config.js
options: {
transformAssetUrls: {
'*': 'style'
}
}
- Goto
vue-loaderdirectory, executenpm install path/to/component-utils - Add
stylewith background image to the example page
<template lang="pug">
div(ok)
h1(:class="$style.red") hello
h1(style="background:url(./image/foo.png)") hello
</template>
- Config
file-loaderinexample/webpack.config.js -
npm run devornpm run build
Then the compiled code is
var render = function() {
var _vm = this
var _h = _vm.$createElement
var _c = _vm._self._c || _h
return _c("div", { attrs: { ok: "" } }, [
_c("h1", { class: _vm.$style.red }, [_vm._v("hello")]),
_c(
"h1",
{
staticStyle: { background: "url(" + __webpack_require__(/*! ../image/foo.png */ "./image/foo.png") + ")" }
},
[_vm._v("hello")]
)
])
}
var staticRenderFns = []
render._withStripped = true
Run on browser:

/cc @yyx990803 I need your opinion on this.
@yyx990803