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

css隔离 #10

Closed
wineSu opened this issue Mar 13, 2021 · 3 comments
Closed

css隔离 #10

wineSu opened this issue Mar 13, 2021 · 3 comments

Comments

@wineSu
Copy link
Contributor

wineSu commented Mar 13, 2021

打包后,子组件的样式会影响到父组件,目前没有做一个很好的css隔离。

@yisar
Copy link
Contributor

yisar commented Mar 13, 2021

要想解决这个问题,只能遍历 css 的 ast,然后把 css 类名给重命名一遍了

svelte 中做了这个工作,可我咋感觉工作量比较大

https://www.github.com/sveltejs/svelte/tree/master/src%2Fcompiler%2Fcompile%2Fcss%2FSelector.ts

vue 是咋做的

@yisar
Copy link
Contributor

yisar commented Mar 13, 2021

使用 vue 的方案

https://github.com/vuejs/vue-loader/blob/v14.2.2/lib/style-compiler/plugins/scope-id.js

input

<style>
.example{
    color:red;
}
</style>

<div>scoped</div>

output

<style>
.example[data-scoped-5558831a] {
  color: red;
}
</style>

<div class="example" data-scoped-5558831a>scoped</div>

@yisar
Copy link
Contributor

yisar commented Mar 14, 2021

暂时搞定了 class 级别的 #12

@yisar yisar closed this as completed Mar 14, 2021
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

No branches or pull requests

2 participants