4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

webpackでcss modulesを使うとz-indexが圧縮されてしまう問題

Last updated at Posted at 2019-08-07

タイトル通り。
Railsでwebpackerをアップグレードした段階で起きるようになったのでwebpackerの問題かと思ったら普通にwebpackでも起こるみたい

環境

  • webpack 3.12.0
  • @rails/webpacker 3.5

症状

  • css moduleでz-indexにどんな値を設定してもコンパイル後は1になる
  • z-index: 10000!importantもコンパイルされるとz-index: 1!importantになる
  • ローカル環境では起こらない
  • こういうのほんとやめて😫

解決

https://github.com/rails/webpacker/issues/1663
ここでproduction.jsに下記を追記しろと仰せだ…

production.js
environment.plugins.get('OptimizeCSSAssets').options.cssProcessorOptions.zindex = false;

とはいえsass-loaderを使っているので最終的にこのような形になりました

production.js
const cssLoader = sassLoader.use.find( lib => lib.loader === 'css-loader' );

cssLoader.options = Object.assign(cssLoader.options, {
 modules: true
});

参考

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?