-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
[Bug Report] custom theme, CSS repeated multiple times #11817
Comments
Translation of this issue: Element UI version OS/Browsers version Vue version Reproduction Link Steps to reproduce The use of webpack CSS to remove the plug-in is not effective CSS style does not repeat CSS style duplication |
I meet the same problem |
@ashen9 请问你解决了吗 |
Same problem on 2.4.6, make my custom template overridden by the default one. |
In my project same styling gets repeated > 10 times. I believe it might have something to do with the webpack setup? |
@ststaynov i had tried to add some plugins to deal css in webpackconfigs,but nothing happend |
Same to me ( I got 7 times), and I used this way http://element-cn.eleme.io/#/zh-CN/component/custom-theme#zai-xiang-mu-zhong-gai-bian-scss-bian-liang |
Did somebody managed to resolve this? :/ |
I have the same problem. |
没有,应该是按需加载时各个组件有重复定义的class,改成全量加载后,element打包去重了 |
Same issue; |
Same problem. |
same here |
"element-ui": "^2.4.5" same problem |
same problem @import "mixins/mixins";
@import "common/var";
@import "button";
@import "./popper"; 是不是这里@import了button导致button样式重复编译
|
same problem v2.6.1 on nuxt |
repeat |
same! and its killing me. |
The problem still exist in version 2.7, how to fix this? |
the same on 2.8.0 |
@Leopoldthecoder @QingWei-Li are you aware of this?
@chenzhq 指出了问题的根源。多处scss 组件模块重复引用了其他模块,导致本地开发会看到多份重复样式,只是因为 production build 的时候被自动dedup了 |
@Leopoldthecoder @QingWei-Li 移除组件内部的重复引用是否可行?还是说因为要兼顾按需引用的特性才搞成这样? |
using fast-sass-loader only fixes it on production? or also on dev? |
@edum18 both. Depend on your This is not an elegant solution. |
Anybody tested on the latest version 2.9.1? |
Yeah, problem is still there... |
same problem here with element-ui@2.5.4 |
I have the same problem with element-ui@2.9.1 |
For people having css rules loaded more than twice I know where the problem lies, a bug exists with the sass loader that will bundle the file every time it is imported in another scss file So if you are importing your 1 - $--color-primary: #00A09E;
$--color-warning: #EE7219;
$--color-danger: #FE4A49;
$--color-info: #00AEEF;
$--color-success: #D6AE15;
$--color-text-primary: #242B35;
$--color-text-secondary: #D6AE15; 2 - @import "colors";
$--font-path: '~element-ui/lib/theme-chalk/fonts';
// The default generated file is
// @import "~element-ui/packages/theme-chalk/src/index";
// If you want to reduce the size further by getting rid of unused css,
// copy the content of the previous file and comment the lines of the elements you don't need:
@import "~element-ui/packages/theme-chalk/src/base.scss";
@import "~element-ui/packages/theme-chalk/src/pagination.scss";
@import "~element-ui/packages/theme-chalk/src/dialog.scss";
@import "~element-ui/packages/theme-chalk/src/autocomplete.scss";
@import "~element-ui/packages/theme-chalk/src/dropdown.scss";
@import "~element-ui/packages/theme-chalk/src/dropdown-menu.scss";
@import "~element-ui/packages/theme-chalk/src/dropdown-item.scss";
@import "~element-ui/packages/theme-chalk/src/menu.scss";
@import "~element-ui/packages/theme-chalk/src/submenu.scss";
@import "~element-ui/packages/theme-chalk/src/menu-item.scss";
@import "~element-ui/packages/theme-chalk/src/menu-item-group.scss";
@import "~element-ui/packages/theme-chalk/src/input.scss";
@import "~element-ui/packages/theme-chalk/src/input-number.scss";
@import "~element-ui/packages/theme-chalk/src/radio.scss";
@import "~element-ui/packages/theme-chalk/src/radio-group.scss";
@import "~element-ui/packages/theme-chalk/src/radio-button.scss";
@import "~element-ui/packages/theme-chalk/src/checkbox.scss";
@import "~element-ui/packages/theme-chalk/src/checkbox-button.scss";
@import "~element-ui/packages/theme-chalk/src/checkbox-group.scss";
@import "~element-ui/packages/theme-chalk/src/switch.scss";
@import "~element-ui/packages/theme-chalk/src/select.scss";
@import "~element-ui/packages/theme-chalk/src/button.scss";
@import "~element-ui/packages/theme-chalk/src/button-group.scss";
@import "~element-ui/packages/theme-chalk/src/table.scss";
@import "~element-ui/packages/theme-chalk/src/table-column.scss";
@import "~element-ui/packages/theme-chalk/src/date-picker.scss";
@import "~element-ui/packages/theme-chalk/src/time-select.scss";
@import "~element-ui/packages/theme-chalk/src/time-picker.scss";
@import "~element-ui/packages/theme-chalk/src/popover.scss";
@import "~element-ui/packages/theme-chalk/src/tooltip.scss";
@import "~element-ui/packages/theme-chalk/src/message-box.scss";
@import "~element-ui/packages/theme-chalk/src/breadcrumb.scss";
@import "~element-ui/packages/theme-chalk/src/breadcrumb-item.scss";
@import "~element-ui/packages/theme-chalk/src/form.scss";
@import "~element-ui/packages/theme-chalk/src/form-item.scss";
@import "~element-ui/packages/theme-chalk/src/tabs.scss";
@import "~element-ui/packages/theme-chalk/src/tab-pane.scss";
@import "~element-ui/packages/theme-chalk/src/tag.scss";
@import "~element-ui/packages/theme-chalk/src/tree.scss";
@import "~element-ui/packages/theme-chalk/src/alert.scss";
@import "~element-ui/packages/theme-chalk/src/notification.scss";
@import "~element-ui/packages/theme-chalk/src/slider.scss";
@import "~element-ui/packages/theme-chalk/src/loading.scss";
@import "~element-ui/packages/theme-chalk/src/row.scss";
@import "~element-ui/packages/theme-chalk/src/col.scss";
@import "~element-ui/packages/theme-chalk/src/upload.scss";
@import "~element-ui/packages/theme-chalk/src/progress.scss";
@import "~element-ui/packages/theme-chalk/src/spinner.scss";
@import "~element-ui/packages/theme-chalk/src/message.scss";
@import "~element-ui/packages/theme-chalk/src/badge.scss";
@import "~element-ui/packages/theme-chalk/src/card.scss";
@import "~element-ui/packages/theme-chalk/src/rate.scss";
@import "~element-ui/packages/theme-chalk/src/steps.scss";
@import "~element-ui/packages/theme-chalk/src/step.scss";
@import "~element-ui/packages/theme-chalk/src/carousel.scss";
@import "~element-ui/packages/theme-chalk/src/scrollbar.scss";
@import "~element-ui/packages/theme-chalk/src/carousel-item.scss";
@import "~element-ui/packages/theme-chalk/src/collapse.scss";
@import "~element-ui/packages/theme-chalk/src/collapse-item.scss";
@import "~element-ui/packages/theme-chalk/src/cascader.scss";
@import "~element-ui/packages/theme-chalk/src/color-picker.scss";
@import "~element-ui/packages/theme-chalk/src/transfer.scss";
@import "~element-ui/packages/theme-chalk/src/container.scss";
@import "~element-ui/packages/theme-chalk/src/header.scss";
@import "~element-ui/packages/theme-chalk/src/aside.scss";
@import "~element-ui/packages/theme-chalk/src/main.scss";
@import "~element-ui/packages/theme-chalk/src/footer.scss";
@import "~element-ui/packages/theme-chalk/src/timeline.scss";
@import "~element-ui/packages/theme-chalk/src/timeline-item.scss";
@import "~element-ui/packages/theme-chalk/src/link.scss";
@import "~element-ui/packages/theme-chalk/src/divider.scss";
@import "~element-ui/packages/theme-chalk/src/image.scss";
@import "~element-ui/packages/theme-chalk/src/calendar.scss";
@import "~element-ui/packages/theme-chalk/src/backtop.scss";
@import "~element-ui/packages/theme-chalk/src/infinite-scroll.scss";
@import "~element-ui/packages/theme-chalk/src/page-header.scss";
@import "~element-ui/packages/theme-chalk/src/cascader-panel.scss";
@import "~element-ui/packages/theme-chalk/src/avatar.scss";
@import "~element-ui/packages/theme-chalk/src/drawer.scss";
@import "~element-ui/packages/theme-chalk/src/popconfirm.scss"; And then in your app's scss (not in js) replace your theme imports (eg: You will also need to get rid of the default element css file (the one without your custom colors) Even though you chose to have a custom theme during generation of the config, the plugin still added those lines in module.exports = {
'presets': [
'@vue/cli-plugin-babel/preset'
],
'plugins': [
[
'component',
{
'libraryName': 'element-ui',
'styleLibraryName': 'theme-chalk' //THIS
}
]
]
} Change it to module.exports = {
'presets': [
'@vue/cli-plugin-babel/preset'
],
'plugins': [
[
'component',
{
'libraryName': 'element-ui',
'style': false
}
]
]
} And the css included will only be your optimized theme's version |
Same Issue. Version: 2.11.1 .el-input__inner style repeated 18 times. @Tofandel After trying your solution, repetition reduced to 11, but it still exists. |
@Tofandel didn't work for me. |
@munjal-vandana did you do both suggestions? I'm pretty sure you're including your custom theme multiple times |
Yes! It was due to the Custom theme. |
@praveenpuglia You know without giving details, I can't help you.. What did you try? What is not working? |
I used whatever you suggested above. Still see a lot of duplicates. Specially with input elements.
|
I use Vue CLI, which use PostCSS. Besides @chenzhq solution, here is another fix with postcss-loader: Edit postcss.config.js to enable cssnano to remove duplicate CSS. module.exports = {
plugins: {
autoprefixer: {},
cssnano: {}
},
}; Be aware compile and hot reload will become slower(around 1s on my laptop). Maybe fast-sass-loader is a better option considering efficiency. P.S. Don't know if element-ui will fix it. Since duplication seems to be intended and is not a real bug. However "import-once" might fix the root casue of this issue once available sass/sass#1094 |
@pingren I tried the solution you mentioned but it didn't really work. :( |
During development as well. Try upgrade your Vue CLI first. According to changelog, it is a new feature introduced in version |
I already have Vue CLI 4.1.2 and I also have the postcss config file. |
Excuse me, has this problem been solved? I met it too. It makes me feel egg pain... |
I've tried all proposed here solutions but nothing works for me. I'm using vue cli and I came up with this solution (it isn't elegant but at least it works):
I'm importing my scss with element variables only once in the application entry point. |
@Tofandel 采用你的方案解决了我遇到的问题,感谢! 关键部分是 |
@andr-canandr Did you check your babel.config.js file for the following? module.exports = {
'presets': [
'@vue/cli-plugin-babel/preset'
],
'plugins': [
[
'component',
{
'libraryName': 'element-ui',
// 'styleLibraryName': 'theme-chalk' //THIS should be
'styleLibraryName': "~src/plugins/theme.scss" //Path to your theme file
}
]
]
} I found all the correct info to setup a theme deeply burried in the custom-theme.md The other documentation is completely incorrect and misleading |
if you are using theme build tool: https://github.com/ElementUI/element-theme you could reference the issue , it solves the problem that removes all the duplicated css classes. just add the arguments
|
emmm...still exist |
any solution? |
@gentlecoder Yes, if you had spent time reading trough the comments. Instead of notifying the 38 participants in this thread. |
You can import components without CSS by importing them from the lib folder. Let's use a Tooltip as an example. You would import the component like so: And then you import your SCSS only once: Hope that helps. |
Is there any update on this problem? |
Encounted when use vite, no solution? |
In the vue-cli 4.x version, your method is invalid. Changing to my method can solve the problem of duplication of development environment styles. But it is not perfect, and it will cause the hot update of the style to fail. Modify vue.config.js and add the following configuration const cssnanoOptions = {
preset: [
"default",
{
mergeLonghand: false,
cssDeclarationSorter: false
}
]
};
module.exports = {
css: {
extract: true
},
chainWebpack: config => {
config.when(process.env.NODE_ENV === "development", config => {
config
.plugin("optimize-css")
.use(require("@intervolga/optimize-cssnano-plugin"), [
{
sourceMap: true,
cssnanoOptions
}
]);
});
}
} |
thx! this works for me. |
最近也遇到这样的问题,尝试了上面的解决方法并没有解决问题,最后直接使用工具生成css,再进行引入解决了,不过我的需求,只是简单的修改主题配色; 工具:https://elementui.github.io/theme-chalk-preview/#/zh-CN
|
Element UI version
2.4.2
OS/Browsers version
ubuntu16.4
Vue version
2.5.17-beta.0
Reproduction Link
https://jsfiddle.net/mmx38qxw/localproject
Steps to reproduce
按照官网2种自定义主题步骤操作,设置好新的主题后,打开项目页面,从控制台可以看到button,input等空间的样式重复多次,有4次,7次甚至更多次.
使用webpack css去重插件也不生效
What is Expected?
css样式不重复
What is actually happening?
css样式重复
The text was updated successfully, but these errors were encountered: