From ab6d8f48deec2c1b85bae1e5ff9b8523a1491a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Thu, 14 Sep 2023 09:11:41 +0200 Subject: [PATCH] Use the @babel/preset-env to selecte working list of browser --- buildtools/webpack.api.js | 10 +++++++--- buildtools/webpack.commons.js | 24 ++++++++++++------------ buildtools/webpack.config.dll.js | 12 +++++++++--- buildtools/webpack.share.js | 25 +++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 18 deletions(-) create mode 100644 buildtools/webpack.share.js diff --git a/buildtools/webpack.api.js b/buildtools/webpack.api.js index 6cbc28aa5648..eb20757dd07b 100644 --- a/buildtools/webpack.api.js +++ b/buildtools/webpack.api.js @@ -39,9 +39,13 @@ module.exports = (env, argv) => { options: { babelrc: false, comments: false, - plugins: [ - require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'), - require.resolve('@babel/plugin-proposal-optional-chaining'), + presets: [ + '@babel/preset-env', + { + targets: require('./webpack.share').browsers, + modules: false, + loose: true, + }, ], }, }, diff --git a/buildtools/webpack.commons.js b/buildtools/webpack.commons.js index 47408cb53a2f..6af0c4f7175d 100644 --- a/buildtools/webpack.commons.js +++ b/buildtools/webpack.commons.js @@ -49,6 +49,14 @@ module.exports = function (config) { $: 'jquery', }); + const babelPresetEnv = [ + require.resolve('@babel/preset-env'), + { + targets: config.browsers || require('./webpack.share').browsers, + loose: true, + }, + ]; + // Expose corejs-typeahead as window.Bloodhound const typeaheadRule = { test: require.resolve('corejs-typeahead'), @@ -144,6 +152,7 @@ module.exports = function (config) { assumptions: { setPublicClassFields: true, }, + presets: [babelPresetEnv], plugins: [ [ require.resolve('@babel/plugin-transform-typescript'), @@ -151,9 +160,6 @@ module.exports = function (config) { {allowDeclareFields: true}, ], [require.resolve('@babel/plugin-proposal-decorators'), {decoratorsBeforeExport: true}], - require.resolve('@babel/plugin-proposal-class-properties'), - require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'), - require.resolve('@babel/plugin-proposal-optional-chaining'), ], }, }, @@ -173,11 +179,8 @@ module.exports = function (config) { options: { babelrc: false, comments: false, - plugins: [ - require.resolve('babel-plugin-angularjs-annotate'), - require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'), - require.resolve('@babel/plugin-proposal-optional-chaining'), - ], + presets: [babelPresetEnv], + plugins: [require.resolve('babel-plugin-angularjs-annotate')], }, }, }; @@ -200,10 +203,7 @@ module.exports = function (config) { options: { babelrc: false, comments: false, - plugins: [ - require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'), - require.resolve('@babel/plugin-proposal-optional-chaining'), - ], + presets: [babelPresetEnv], }, }, }; diff --git a/buildtools/webpack.config.dll.js b/buildtools/webpack.config.dll.js index 10283f2e8d4b..332e25780b3b 100644 --- a/buildtools/webpack.config.dll.js +++ b/buildtools/webpack.config.dll.js @@ -41,9 +41,15 @@ module.exports = { options: { babelrc: false, comments: false, - plugins: [ - require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'), - require.resolve('@babel/plugin-proposal-optional-chaining'), + presets: [ + [ + require.resolve('@babel/preset-env'), + { + targets: require('./webpack.share').browsers, + modules: false, + loose: true, + }, + ], ], }, }, diff --git a/buildtools/webpack.share.js b/buildtools/webpack.share.js new file mode 100644 index 000000000000..fd3cd849222a --- /dev/null +++ b/buildtools/webpack.share.js @@ -0,0 +1,25 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018-2023 Camptocamp SA +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +// the Software, and to permit persons to whom the Software is furnished to do so, +// subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +module.exports = { + // see: npx browserslist '> 0.7% in CH or > 0.7% in FR or Firefox ESR' + browsers: 'defaults, > 0.1% in CH, > 0.1% in FR, Firefox ESR and supports es6-class and not iOS < 10', +};