diff --git a/babel.config.js b/babel.config.js index d54a01b..ae82baa 100644 --- a/babel.config.js +++ b/babel.config.js @@ -8,3 +8,6 @@ module.exports = { }] ] } + + + diff --git a/config/index.js b/config/index.js index 7add554..ce7f69b 100644 --- a/config/index.js +++ b/config/index.js @@ -27,7 +27,10 @@ const config = { }, h5: { + // 默认会编译为 es5,修改为 es2017 或更高 + esnext: true, webpackChain(chain) { + chain.output.filename("static/js/[name].[contenthash:8].js"); chain.output.chunkFilename("static/js/[name].[contenthash:8].js"); chain @@ -54,6 +57,7 @@ const config = { simplify: true, // 开启简化,提高性能 // 禁用对 async/await 的转换 target: "browser", // 或设置为适合目标环境的 ECMAScript 版本 + disableOptimizations: true, // 禁用某些优化来避免处理 async/await }, ["**/*.js", "!node_modules/**"], // 避免对 node_modules 进行混淆 @@ -125,6 +129,10 @@ const config = { }, // 允许特定域名访问 allowedHosts: ["nomadyt.com", "localhost", ".nomadyt.com"], // 允许所有 *.nomadyt.com 子域访问 + // ⬇️ 关键配置:禁用 overlay 错误弹出 + client: { + overlay: false, + }, }, htmlPluginOption: { favicon: path.resolve(__dirname, "..", "src", "images", "youtube.ico"), // 同样处理 favicon 路径 @@ -135,7 +143,8 @@ const config = { }, }, - target: ["web", "browserslist:> 0.25%, not dead"], + // target: ["web", "browserslist:> 0.25%, not dead"], + target: ["web", "es2017"], // 关键点! }, }; diff --git a/package.json b/package.json index 4b48816..b6abda8 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ }, "devDependencies": { "@babel/core": "^7.8.0", + "@babel/preset-env": "^7.26.9", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5", "@tarojs/cli": "3.6.20", "@tarojs/taro-loader": "3.6.20", @@ -73,6 +74,7 @@ "javascript-obfuscator": "^4.1.1", "postcss": "^8.4.18", "react-refresh": "^0.11.0", + "regenerator-runtime": "^0.14.1", "stylelint": "9.3.0", "ts-node": "^10.9.1", "typescript": "^4.1.0", diff --git a/src/app.js b/src/app.js index ccaee58..12313d8 100644 --- a/src/app.js +++ b/src/app.js @@ -5,6 +5,9 @@ import './app.scss' import 'animate.css'; import 'taro-ui/dist/style/index.scss' // 全局引入一次即可 +import 'core-js/stable'; +import 'regenerator-runtime/runtime'; // 用于支持 async/await + /** * 有数埋点SDK 默认配置 * 使用方法请参考文档 https://mp.zhls.qq.com/youshu-docs/develop/sdk/Taro.html @@ -68,7 +71,7 @@ class App extends Component { // this.props.children 是将要会渲染的页面 render () { - return this.props.children + return this.props?.children } } diff --git a/yarn.lock b/yarn.lock index ee325a2..1a7cdeb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -912,7 +912,7 @@ "@babel/helper-create-regexp-features-plugin" "^7.25.9" "@babel/helper-plugin-utils" "^7.25.9" -"@babel/preset-env@^7.11.0", "@babel/preset-env@^7.14.5": +"@babel/preset-env@^7.11.0", "@babel/preset-env@^7.14.5", "@babel/preset-env@^7.26.9": version "7.26.9" resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.26.9.tgz#2ec64e903d0efe743699f77a10bdf7955c2123c3" integrity sha512-vX3qPGE8sEKEAZCWk05k3cpTAE3/nOYca++JA+Rd0z2NCNzabmYvEiSShKzm10zdquOIAVXsy2Ei/DTW34KlKQ== @@ -11021,7 +11021,7 @@ regenerator-runtime@0.11: resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" integrity sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg== -regenerator-runtime@^0.14.0: +regenerator-runtime@^0.14.0, regenerator-runtime@^0.14.1: version "0.14.1" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz#356ade10263f685dda125100cd862c1db895327f" integrity sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==