-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
supports uri fragment in static style transformed require #37
base: master
Are you sure you want to change the base?
Conversation
@@ -6,6 +6,8 @@ export interface Attr { | |||
export interface ASTNode { | |||
tag: string | |||
attrs: Attr[] | |||
staticStyle?: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not convinced in changing the interface of ASTNode, it's not necessary to surface staticStyle from attrs. Also now codegen has to modified to treat styles differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not convinced in changing the interface of ASTNode, it's not necessary to surface staticStyle from attrs.
since attrs
doesn't contain style
Also now codegen has to modified to treat styles differently.
Agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather extend implementation of rewrite
method to handle asset URLs in inline style.
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.
<div style="background: url('/some/image/path/some-file.png')">
and
<div :style="`background: url('/some/image/path/${filename}.png')`">
<div :style="`background: ${backgroundLink}`">
<div :style="`${backgroundStyle}`">
would produce same inline style but only first can be statically transformed to require
statement. It leaves us with very confused state.
In fact,
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')}` --> |
On compiled render function vnode data, |
Yes, I tested in Here is my test steps:
options: {
transformAssetUrls: {
'*': 'style'
}
}
<template lang="pug">
div(ok)
h1(:class="$style.red") hello
h1(style="background:url(./image/foo.png)") hello
</template>
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 |
/cc @yyx990803 I need your opinion on this. |
resolved vuejs/vue-loader#646