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

build-scripts如何支持最新的javascript语法 #138

Open
starsoul666 opened this issue Dec 4, 2023 · 3 comments
Open

build-scripts如何支持最新的javascript语法 #138

starsoul666 opened this issue Dec 4, 2023 · 3 comments

Comments

@starsoul666
Copy link

第三方依赖包使用了最新的javascript语法,例如?. 代码构建的时候会报错,如何更新corejs版本,支持最新的js语法

@Osub
Copy link

Osub commented Jan 6, 2024

image

@Dogtiti
Copy link

Dogtiti commented Feb 2, 2024

+1

@Dogtiti
Copy link

Dogtiti commented Feb 2, 2024

@starsoul666

module.exports = ({ onGetWebpackConfig }) => {
  onGetWebpackConfig((config) => {
    // 确保babel-loader配置存在,然后添加optional chaining插件
    config.module
      .rule('js')
      .test(/\.jsx?$/)
      .use('babel-loader')
      .loader('babel-loader')
      .options({
        presets: ['@babel/preset-env', '@babel/preset-react'],
        plugins: ['@babel/plugin-proposal-optional-chaining'],
      });
  });
};

研究了一下这样可以解决问题,看看你那适用不

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

3 participants