build-scripts icon indicating copy to clipboard operation
build-scripts copied to clipboard

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

Open starsoul666 opened this issue 2 years ago • 3 comments

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

starsoul666 avatar Dec 04 '23 07:12 starsoul666

image

Osub avatar Jan 06 '24 02:01 Osub

+1

Dogtiti avatar Feb 02 '24 06:02 Dogtiti

@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'],
      });
  });
};

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

Dogtiti avatar Feb 02 '24 07:02 Dogtiti