Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

father v4 如何覆盖默认babel preset 配置 #567

Open
sharemeans opened this issue Jan 11, 2023 · 4 comments
Open

father v4 如何覆盖默认babel preset 配置 #567

sharemeans opened this issue Jan 11, 2023 · 4 comments

Comments

@sharemeans
Copy link

想配置@umi/babel-preset-umi的loose为true。
理由:class 继承出现属性重复定义的情况,由于defineProperty重复定义属性会报错,有什么解决办法么。

@fz6m
Copy link
Contributor

fz6m commented Jan 11, 2023

// .fatherrc.ts

export default defineConfig({
  umd: {
    chainWebpack(memo, { webpack }) {
      const RULES = ['src', 'jsx-ts-tsx', 'extra-src']
      RULES.forEach(rule => {
        memo.module.rule(rule).use('babel-loader').tap((options) => {
          options.presets[0][1].presetEnv.loose = true;
          return options
        })
      })
      return memo
    },
  },
})

但是不建议你这么用。

@hstarorg
Copy link

如果是打包 esm 呢?有办法么?

@wozien
Copy link

wozien commented May 9, 2023

// .fatherrc.ts
import { defineConfig } from 'father';

export default defineConfig({
  esm: {
    output: 'es',
  },
  extraBabelPlugins: [
    [
      require.resolve(
        '@umijs/bundler-utils/compiled/babel/plugin-proposal-class-properties',
      ),
      { loose: true },
    ],
    [
      require.resolve(
        '@umijs/bundler-utils/compiled/babel/plugin-proposal-private-methods',
      ),
      {
        loose: true,
      },
    ],
    [
      require.resolve(
        '@umijs/bundler-utils/compiled/babel/plugin-proposal-private-property-in-object',
      ),
      {
        loose: true,
      },
    ],
  ]
});

可以暂时这么配置解决

@wozien
Copy link

wozien commented May 9, 2023

后续希望father能暴露一个配置参数

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants