diff --git a/.browserslistrc b/.browserslistrc index 86481f8e08..516fec9cec 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -10,6 +10,12 @@ supports es6-module-dynamic-import not Safari < 13 not iOS < 13 +# Exclude KaiOS, QQ, and UC browsers due to lack of sufficient feature support data +# Babel ignores these automatically, but we need here for Webpack to output ESM with dynamic imports +not KaiOS > 0 +not QQAndroid > 0 +not UCAndroid > 0 + # Exclude unsupported browsers not dead diff --git a/build-scripts/bundle.cjs b/build-scripts/bundle.cjs index a6d14f18c8..f840f21762 100644 --- a/build-scripts/bundle.cjs +++ b/build-scripts/bundle.cjs @@ -77,6 +77,7 @@ module.exports.htmlMinifierOptions = { module.exports.terserOptions = ({ latestBuild, isTestBuild }) => ({ safari10: !latestBuild, ecma: latestBuild ? 2015 : 5, + module: latestBuild, format: { comments: false }, sourceMap: !isTestBuild, }); diff --git a/build-scripts/webpack.cjs b/build-scripts/webpack.cjs index 58cc184ca8..418037d9da 100644 --- a/build-scripts/webpack.cjs +++ b/build-scripts/webpack.cjs @@ -41,7 +41,7 @@ const createWebpackConfig = ({ return { name, mode: isProdBuild ? "production" : "development", - target: ["web", latestBuild ? "es2017" : "es5"], + target: `browserslist:${latestBuild ? "modern" : "legacy"}`, // For tests/CI, source maps are skipped to gain build speed // For production, generate source maps for accurate stack traces without source code // For development, generate "cheap" versions that can map to original line numbers @@ -163,6 +163,7 @@ const createWebpackConfig = ({ }, }, output: { + module: latestBuild, filename: ({ chunk }) => !isProdBuild || isStatsBuild || dontHash.has(chunk.name) ? "[name].js" @@ -196,7 +197,7 @@ const createWebpackConfig = ({ : undefined, }, experiments: { - topLevelAwait: true, + outputModule: true, }, }; }; diff --git a/test/webpack.config.js b/test/webpack.config.js index 20e1e163e3..ad593b58aa 100644 --- a/test/webpack.config.js +++ b/test/webpack.config.js @@ -1,8 +1,13 @@ import webpack from "../build-scripts/webpack.cjs"; -export default webpack.createAppConfig({ +const config = webpack.createAppConfig({ isProdBuild: false, latestBuild: true, isStatsBuild: false, isTestBuild: true, }); + +// instant-mocha forces a CJS library, so cannot output ESM +config.output.module = false; + +export default config;