4
2

More than 5 years have passed since last update.

@nuxt/babel-preset-appのtargetsにpackage.jsonのbrowserslistを使う

Posted at

はじめに

ChromeBot(Chrome41相当らしい)の対策にBabelのブラウザターゲットの設定をしたくなって調べたのをメモ

package.json

package.json
"browserslist": [
  "last 2 versions",
  "ie >= 9",
  "chrome >= 41"
]

nuxt.config.js

nuxt.config.js
const pkg = require('./package')

/* 中略 */

build: {
  babel: {
    presets({ isServer }) {
      return [
        [
          require.resolve('@nuxt/babel-preset-app'),
          {
            targets: isServer
              ? { node: 'current' }
              : { browsers: pkg.browserslist }
          }
        ]
      ]
    }
  }
}

おわりに

どうせならAutoprefixerのほうと設定を同一にしようとなった結果だったりするのだけど
Chrome41はあくまでChromeBot対策なのでAutoprefixerとは設定を分けたほうが良いのかなーと思ったりもする。
ただ、自分の手元ではそんなにファイルサイズ変わらなかったので同一で良いかなとなった。

参考

https://github.com/nuxt/nuxt.js/issues/4900
https://github.com/nuxt/nuxt.js/issues/271

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