Skip to content
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

Merged
merged 18 commits into from
Apr 1, 2017
Merged

add style scoped #86

merged 18 commits into from
Apr 1, 2017

Conversation

dolymood
Copy link
Contributor

增加 style 的 scoped 处理

@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.855% when pulling 2863978 on dolymood:style-scope into ab6e929 on wepyjs:master.

@Gcaufy Gcaufy mentioned this pull request Mar 31, 2017
@Gcaufy
Copy link
Collaborator

Gcaufy commented Mar 31, 2017

#79

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') {
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我的锅

@@ -104,26 +104,39 @@ export default {

xml = this.createParser().parseFromString(content);

const moduleId = simpleId(filepath);
const moduleId = util.genId(filepath);

let rst = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其实对于 template 和 script 来说,多个标签完全是没有意义的事情,所以我觉得这里完全可以将 style 定义为数组,其它的就定义成 object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里其实做的时候考虑 把他们合并成一块,我觉得如果要约定的话,就可以直接约定死 style 可以是多个,template 和 script 最多只能有一个,如果发现出现多个,是否可以直接强制报错了?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对的。这样实现最好,如果不报错,那默认也是被覆盖。
因为暂时来看 template 和 script 完全没有多标签的需要

@@ -371,7 +388,7 @@ export default {
// 设置 scoped 无效
wpy.style.scoped = '';
Copy link
Collaborator

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 写代码时可能更好理解。

typeRst.blocks.forEach((block) => {
typeRst.code += block.code || '';
typeRst.src = typeRst.src || block.src || '';
typeRst.type = typeRst.type || block.type || '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

假设存在两个style标签,一个为 less 一个为 sass,那么这里的 type 就没有意义了

@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.855% when pulling 93eb497 on dolymood:style-scope into ab6e929 on wepyjs:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.855% when pulling c398708 on dolymood:style-scope into ab6e929 on wepyjs:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.855% when pulling 809d6f5 on dolymood:style-scope into ab6e929 on wepyjs:master.

@@ -12,7 +12,7 @@ const LANG_MAP = {
};

export default {
compile (styles, requires, opath, moduleId, app) {
compile (styles, requires, opath, moduleId, isApp) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

能否在之前获取wpy的时候就将wpy中的scoped设置成false, 而不是把参数传进这里呢

@@ -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);
Copy link
Collaborator

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);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其实这里就是不想再次循环了
不过还是前置比较妥一点

} 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同理,这里可以直接清空wpy.template

@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.855% when pulling 41c1ff1 on dolymood:style-scope into ab6e929 on wepyjs:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.855% when pulling 5101076 on dolymood:style-scope into 0f56c47 on wepyjs:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.855% when pulling a320421 on dolymood:style-scope into 0f56c47 on wepyjs:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.855% when pulling d7ab267 on dolymood:style-scope into 0f56c47 on wepyjs:master.

@Gcaufy Gcaufy merged commit c667179 into Tencent:master Apr 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants