From 3eea3c44394a3af7f8f43dd59dd1630ccf72307c 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 select working list of browser Partially revert https://github.com/camptocamp/ngeo/commit/5179ba0466c87deb2c745a2efa86d3a848020dce#diff-cac2d12981119fd024d4f6ec349cc35509079b5f3601a5ceaf32920535788047 --- buildtools/webpack.api.js | 10 +++++++--- buildtools/webpack.commons.js | 25 +++++++++++++------------ buildtools/webpack.config.dll.js | 10 +++++++--- buildtools/webpack.share.js | 25 +++++++++++++++++++++++++ webpack.config.js | 5 +---- 5 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 buildtools/webpack.share.js diff --git a/buildtools/webpack.api.js b/buildtools/webpack.api.js index 6cbc28aa5648..d113132634db 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, + }, + ], ], }, }, diff --git a/buildtools/webpack.commons.js b/buildtools/webpack.commons.js index 47408cb53a2f..6f7bc07ff750 100644 --- a/buildtools/webpack.commons.js +++ b/buildtools/webpack.commons.js @@ -49,6 +49,15 @@ module.exports = function (config) { $: 'jquery', }); + const babelPresetEnv = [ + require.resolve('@babel/preset-env'), + { + targets: config.browsers || require('./webpack.share').browsers, + debug: true, + loose: true, + }, + ]; + // Expose corejs-typeahead as window.Bloodhound const typeaheadRule = { test: require.resolve('corejs-typeahead'), @@ -144,6 +153,7 @@ module.exports = function (config) { assumptions: { setPublicClassFields: true, }, + presets: [babelPresetEnv], plugins: [ [ require.resolve('@babel/plugin-transform-typescript'), @@ -151,9 +161,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 +180,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 +204,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..cea538605c34 100644 --- a/buildtools/webpack.config.dll.js +++ b/buildtools/webpack.config.dll.js @@ -41,9 +41,13 @@ 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, + }, + ], ], }, }, 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', +}; diff --git a/webpack.config.js b/webpack.config.js index d907cbb964a0..af0120118f47 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,6 +1,6 @@ // The MIT License (MIT) // -// Copyright (c) 2017-2021 Camptocamp SA +// Copyright (c) 2017-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 @@ -32,9 +32,6 @@ module.exports = (env, args) => { case 'dist': common_config.nodll = true; break; - case 'ngeo-examples': - case 'gmf-examples': - common_config.browsers = ['> 0.5% in CH', '> 0.5% in FR', 'Firefox ESR', 'ie 11']; } let config = require('./buildtools/webpack.commons')(common_config);