Webpack: After built the z-index changed

Created on 21 Mar 2017  路  10Comments  路  Source: vuejs-templates/webpack

Version

latest[mybe not just]
[zIndexBug.zip](https://github.com/vuejs-templates/webpack/files/858212/zIndexBug.zip)

Steps to reproduce

  • Just make a vue component锛寃rite z-index in style
  • Run command: npm run dev锛宔verything fine
  • Run command: 'npm run build`锛寃hat a mess...my z-index value changed

I think the z-index value shouldn't be changed锛宐ecause we may use the third party plugin like jQuery plugin which could use z-index. In this condition, the z-index calculation is unnecessary, and make mistakes.

What is expected?

keep my z-index value
dev

What is actually happening?

my z-index changed
built

Most helpful comment

I noticed that the webpack/template/build/webpack.prod.conf.js file has been changed by yyx990803.

only use safe optimizations for css minification

So everything goes well. By the way, thanks.

All 10 comments

You likely set the same class somewhere else, with z-index: 1

During production, all CSS is extracted in one file and minified, which also removes duplicate definitions - and in this case, the duplicate with z-index: 1 was the "survivor".

No, absolutely not.
I just want to override z-index that setted in other plugin.
For example, I set z-index: 2 in a.js, then I import it at b.js, and override z-index: 3 in b.js, it wouldn't work.

For example, I set z-index: 2 in a.js, then I import it at b.js, and override z-index: 3 , it wouldn't work.

This is exactly what I am talking about, though. If you override global styles in a component without using the scopedfeature, the latest one will override all other versions. CSS is global by default.

If you still disagree, please provide a repository with a minimal reproduction for me to check out.

I write a simple demo.

  • npm run dev: You will see the blue sky
  • npm run build: You will see the tan land

Maybe you would ask why set z-index in the DOM, because we cannot guarantee what component will be used. It just like using a component doesn't write with Vue.

zIndexBug.zip

Just run into the same problem. In my single .vue file, I set the modal-mask 'z-index:999', and alert 'z-index:1000' (both in scoped style tag)
2

After building, they are changed into 1 and 2.
1
I think it is the same issue as : https://github.com/ben-eb/gulp-cssnano/issues/8
Since I search in the node_modules folder and find cssnano installed.
3

Ah I see, so at the root, this is an issue with css-loader / cssnano default settings.

I think we should be able to fix this in the webpack config for css-loader.

Thanks for investigating! :)

Hm, I'm currently trying to test my fix, but I can't reproduce the problematic behaviour, even if I set minimize: { zindex: true } in the css-loader's options...

I noticed that the webpack/template/build/webpack.prod.conf.js file has been changed by yyx990803.

only use safe optimizations for css minification

So everything goes well. By the way, thanks.

Oh, I missed that, thanks for the pointer!

@LinusBorg should this be added in the Readme.md file as well.

new OptimizeCssAssetsPlugin({
          cssProcessorOptions: {
            safe: true
          }
        }),
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jlucrob picture jlucrob  路  3Comments

dann95 picture dann95  路  3Comments

nicolas-t picture nicolas-t  路  4Comments

akoboy picture akoboy  路  3Comments

connor11528 picture connor11528  路  3Comments