evanw/esbuild

某些情况下babelPlugins不生效

Closed this issue · 2 comments

build.json

{
  "eslint": true,
  "store": true,
  "dropLogLevel": "log",
  "hash": "contenthash",
  "modeConfig": {
    "dev": {
      "sourceMap": true
    },
    "test": {
      "sourceMap": true
    },
    "uat": {
      "sourceMap": true
    }
  },
  "minify": {
    "type": "esbuild",
    "options": {
      "target": "es2016",
      "css": true
    }
  },
  "plugins": [
    [
      "build-plugin-antd",
      {
        "themeConfig": {
          "primary-color": "#205FED"
        }
      }
    ],
    [
      "build-plugin-moment-locales",
      {
        "locales": ["zh-cn"]
      }
    ],
    [
      "build-plugin-icestark",
      {
        "uniqueName": "frameworkJsonp"
      }
    ],
    "./build.plugin.js"
  ],
  "babelPresets": [["@babel/preset-react", { "runtime": "automatic" }]],
  "babelPlugins": [
    "@babel/plugin-proposal-async-generator-functions"
  ],
  "compileDependencies": ["axios"],
  "browserslist": {
    "chrome": 49,
    "ie": 11
  }
}

间接依赖中使用了高版本axios,用到async generator语法, esbuild无法transform:

ERR! WEBPACK HookWebpackError: Transform failed with 2 errors:
ERR! WEBPACK js/index.4f8396b638781611c0d7.js:183158:18: ERROR: Transforming async generator functions to the configured target environment ("es2016") is not supported yet
ERR! WEBPACK js/index.4f8396b638781611c0d7.js:183164:19: ERROR: Transforming async generator functions to the configured target environment ("es2016") is not supported yet
ERR! WEBPACK     at makeWebpackError (D:\xxxx\node_modules\.pnpm\@builder+pack@0.6.5\node_modules\@builder\pack\deps\webpack\bundle5.js:68022:9)
ERR! WEBPACK     at D:\xxxx\node_modules\.pnpm\@builder+pack@0.6.5\node_modules\@builder\pack\deps\webpack\bundle5.js:51531:12   
ERR! WEBPACK     at eval (eval at create (D:\xxxx\node_modules\.pnpm\@builder+pack@0.6.5\node_modules\@builder\pack\deps\webpack\bundle5.js:40256:10), <anonymous>:68:1)
ERR! WEBPACK     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

From what I can search for you seems to post a config for ice.js which seems build on top of webpack, which seems has dropped the esbuild minifier option. In that case you shouldn't expect any side (both esbuild or ice.js) to "fix" your issue.

esbuild cannot lower some syntaxes because either they require special runtime (like babel runtime regenerator) or they are too complex to implement without making esbuild slower (like lowering const-and-let to es5 while preserving its semantic). This behavior is documented.

For those projects using esbuild as a step of its build process, the ideal way should be always using esnext in the middle steps (so that there's no performance loss) and only apply syntax lowering at the end. If the target is too low that esbuild cannot support, they can add a babel step to help lowering.

From what I can search for you seems to post a config for ice.js which seems build on top of webpack, which seems has dropped the esbuild minifier option. In that case you shouldn't expect any side (both esbuild or ice.js) to "fix" your issue.

esbuild cannot lower some syntaxes because either they require special runtime (like babel runtime regenerator) or they are too complex to implement without making esbuild slower (like lowering const-and-let to es5 while preserving its semantic). This behavior is documented.

For those projects using esbuild as a step of its build process, the ideal way should be always using esnext in the middle steps (so that there's no performance loss) and only apply syntax lowering at the end. If the target is too low that esbuild cannot support, they can add a babel step to help lowering.

My fault, should have been posted in icejs repo