-
Notifications
You must be signed in to change notification settings - Fork 3k
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
add style scoped #86
add style scoped #86
Conversation
let config = util.getConfig(); | ||
let src = cache.getSrc(); | ||
let dist = cache.getDist(); | ||
let ext = cache.getExt(); | ||
const filepath = path.join(opath.dir, opath.base); | ||
|
||
if (arguments.length === 2) { | ||
if (typeof styleRst === '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.
typeof 为 string 时 filepath 此时应该是undefined吧,这里应该是个BUG
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.
我的锅
packages/wepy-cli/src/compile-wpy.js
Outdated
@@ -104,26 +104,39 @@ export default { | |||
|
|||
xml = this.createParser().parseFromString(content); | |||
|
|||
const moduleId = simpleId(filepath); | |||
const moduleId = util.genId(filepath); | |||
|
|||
let rst = { |
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.
其实对于 template 和 script 来说,多个标签完全是没有意义的事情,所以我觉得这里完全可以将 style 定义为数组,其它的就定义成 object
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.
这里其实做的时候考虑 把他们合并成一块,我觉得如果要约定的话,就可以直接约定死 style 可以是多个,template 和 script 最多只能有一个,如果发现出现多个,是否可以直接强制报错了?
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.
对的。这样实现最好,如果不报错,那默认也是被覆盖。
因为暂时来看 template 和 script 完全没有多标签的需要
packages/wepy-cli/src/compile-wpy.js
Outdated
@@ -371,7 +388,7 @@ export default { | |||
// 设置 scoped 无效 | |||
wpy.style.scoped = ''; |
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.
scoped 目前只存在两个值, true or false, 所以使用 boolean 写代码时可能更好理解。
packages/wepy-cli/src/util.js
Outdated
typeRst.blocks.forEach((block) => { | ||
typeRst.code += block.code || ''; | ||
typeRst.src = typeRst.src || block.src || ''; | ||
typeRst.type = typeRst.type || block.type || ''; |
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.
假设存在两个style标签,一个为 less 一个为 sass,那么这里的 type 就没有意义了
@@ -12,7 +12,7 @@ const LANG_MAP = { | |||
}; | |||
|
|||
export default { | |||
compile (styles, requires, opath, moduleId, app) { | |||
compile (styles, requires, opath, moduleId, isApp) { |
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.
能否在之前获取wpy的时候就将wpy中的scoped设置成false, 而不是把参数传进这里呢
packages/wepy-cli/src/compile-wpy.js
Outdated
@@ -381,12 +383,12 @@ export default { | |||
requires.push(path.join(opath.dir, wpy.template.components[k])); | |||
} | |||
} | |||
cStyle.compile(wpy.style, requires, opath, wpy.moduleId, type === 'app'); | |||
cStyle.compile(wpy.style, requires, opath, wpy.moduleId, isApp); |
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.
wpy.style.forEach(v=>v.scoped =false);
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.
其实这里就是不想再次循环了
不过还是前置比较妥一点
packages/wepy-cli/src/compile-wpy.js
Outdated
} else { | ||
this.remove(opath, 'wxss'); | ||
} | ||
|
||
if (wpy.template.code && (type !== 'app' && type !== 'component')) { // App 和 Component 不编译 wxml | ||
if (wpy.template.code && (!isApp && type !== 'component')) { // App 和 Component 不编译 wxml |
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.
同理,这里可以直接清空wpy.template
增加 style 的 scoped 处理