鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ Rollup報(bào)錯(cuò),提示關(guān)閉模塊轉(zhuǎn)換

Rollup報(bào)錯(cuò),提示關(guān)閉模塊轉(zhuǎn)換

我在用Jest測(cè)試JavaScript腳本,使用了ES6 Modules,所以用babel來轉(zhuǎn)換ESM到CommonJS,但是Rollup打包的時(shí)候提示我關(guān)閉?,F(xiàn)在打開了之后就不能跑Rollup,關(guān)閉了就不能跑Jest里的ESM。請(qǐng)問各位是如何解決的呢?

[!] (babel plugin) Error: It looks like your Babel configuration specifies a module transformer. Please disable it. See https://github.com/rollup/rol... for more information
回答
編輯回答
奧特蛋

babel可以配置env

{
  "env": {
    "test": {
      "presets": ["env"]
    },
    "production": {
      "presets": [
        ["env",
        {
          "modules": false
        }]
      ]
    }
  },
  "ignore": [
    "dist/*.js"
  ]
}

源自:.babelrc#env-option

然后,可以在npm scripts里配置BABEL_ENV

"scripts": {
  "test": "cross-env BABEL_ENV='test' jest --watchAll --coverage",
  "prettier": "prettier --write --no-semi {.,test}/*.js",
  "build": "cross-env BABEL_ENV='production' rollup -c"
}
2017年3月5日 23:54