LoginSignup
2
0

More than 5 years have passed since last update.

PostCSS + Webpack でグローバルなCSS変数

Last updated at Posted at 2017-05-24

PostCSS + Webpack で、レスポンシブなサイトを作っている。

下記のようにグローバルな変数を定義して、

$desktop: "only screen and (min-width: 769px)";

こういうふうに使いたい。

@media $desktop {
  display: none;
}

PostCSSの@import とかでつまづいたので、結局、postcss.config.jsに直接書いて解決した。

postcss.config.js
module.exports = {
  plugins: [
    require('precss'),
    require('autoprefixer'),
    require('postcss-simple-vars')({
      variables: require('./src/css/variables.css.js')
    }),
  ]
}
src/css/variables.css.js
module.exports = {
  desktop: 'screen and (min-width: 769px)',
}

参考

2
0
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
2
0