From 7878f0197df14da1e7b202a00d26b163288e3e32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=B0=91?= Date: Mon, 14 Feb 2022 11:50:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8D=87=E7=BA=A7taro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- packages/vantui-demo/babel.config.js | 55 ++--------------- .../vantui-demo/config/webpack/h5Chain.js | 59 ++----------------- .../vantui-demo/config/webpack/miniChain.js | 58 ++---------------- packages/vantui-demo/package.json | 1 + packages/vantui-demo/yarn.lock | 6 +- packages/vantui-doc/docs/home.md | 2 +- 7 files changed, 22 insertions(+), 161 deletions(-) diff --git a/README.md b/README.md index e49b7ee8e..24bfdb114 100644 --- a/README.md +++ b/README.md @@ -94,5 +94,5 @@ ### 快速沟通群
- +
\ No newline at end of file diff --git a/packages/vantui-demo/babel.config.js b/packages/vantui-demo/babel.config.js index 1871d349d..b511448a0 100644 --- a/packages/vantui-demo/babel.config.js +++ b/packages/vantui-demo/babel.config.js @@ -1,63 +1,16 @@ /* eslint-disable @typescript-eslint/no-var-requires */ -const path = require('path') -const apis = require('@tarojs/taro-h5/dist/taroApis') - module.exports = { presets: [ [ - '@antmjs/babel-preset', + 'taro', { - presets: { - env: { - debug: false, - - /** - * false: 不处理polyfill,自己手动引入【全量】 - * usage: 按需加载 polyfill,且不需要手动引入【按需】 - * entry: 必须手动引入,但会根据设置的目标环境全量导入【按环境全量】 - * 注:在 Babel 7.4.0 之后的版本,Babel官方明确建议了不再使用 @babel/polyfill ,建议使用 core-js/stable 和 regenerator-runtime/runtime。本包已经安装了core-js、@babel/plugin-transform-runtime和@babel/runtime,所以选择false或者entry选项的只需要在主文件顶部引入core-js即可 - */ - useBuiltIns: 'usage', - corejs: { version: 3, proposals: false }, - modules: false, // 对es6的模块文件不做转译,以便使用tree shaking、sideEffects等 - }, - react: { - runtime: 'automatic', - }, - typescript: { - isTSX: true, - jsxPragma: 'React', - allExtensions: true, - allowNamespaces: true, - }, - }, - decorators: { - legacy: false, - decoratorsBeforeExport: false, - }, - classProperties: { - loose: false, - }, - runtime: { - absoluteRuntime: path.dirname( - require.resolve('@babel/runtime-corejs3/package.json'), - ), - version: require('@babel/runtime-corejs3/package.json').version, - corejs: false, - helpers: true, // 使用到@babel/runtime - regenerator: true, // 使用到@babel/runtime - useESModules: false, - }, - enableReactRefresh: - process.env.TARO_ENV === 'h5' && process.env.WATCHING === 'true', + framework: 'react', + ts: true, + useBuiltIns: 'usage', }, ], ], plugins: [ - [ - require('babel-plugin-transform-taroapi'), - { packageName: '@tarojs/taro', apis }, - ], // taro可以加,tree-shaking用 [ 'import', { diff --git a/packages/vantui-demo/config/webpack/h5Chain.js b/packages/vantui-demo/config/webpack/h5Chain.js index 176b387fb..ddd2225ca 100644 --- a/packages/vantui-demo/config/webpack/h5Chain.js +++ b/packages/vantui-demo/config/webpack/h5Chain.js @@ -1,6 +1,4 @@ /* eslint-disable @typescript-eslint/no-var-requires */ -const npath = require('path') -const apis = require('@tarojs/taro-h5/dist/taroApis') module.exports = function (chain) { // 内部exclude = [filename => /node_modules/.test(filename) && !(/taro/.test(filename))]; // taro编译由下面compile-node-modules来处理 @@ -13,70 +11,25 @@ module.exports = function (chain) { (/node_modules/.test(filename) && !( /taro/.test(filename) && - !/tarojs[\\/](runtime|shared)/.test(filename) + !/tarojs[\\/](runtime|shared|plugin-platform)/.test(filename) )), ) // node_modules需要二次编译的在这里处理,taro相关的包不能加载polyfill chain.module .rule('compile-node-modules') - .test(/tarojs[\\/](runtime|shared)/i) + .test(/tarojs[\\/](runtime|shared|plugin-platform)/i) .use('taro-loader') .loader(require.resolve('babel-loader')) .options({ presets: [ [ - '@antmjs/babel-preset', + 'taro', { - presets: { - env: { - debug: false, - - /** - * false: 不处理polyfill,自己手动引入【全量】 - * usage: 按需加载 polyfill,且不需要手动引入【按需】 - * entry: 必须手动引入,但会根据设置的目标环境全量导入【按环境全量】 - * 注:在 Babel 7.4.0 之后的版本,Babel官方明确建议了不再使用 @babel/polyfill ,建议使用 core-js/stable 和 regenerator-runtime/runtime。本包已经安装了core-js、@babel/plugin-transform-runtime和@babel/runtime,所以选择false或者entry选项的只需要在主文件顶部引入core-js即可 - */ - useBuiltIns: false, - corejs: false, - modules: false, // 对es6的模块文件不做转译,以便使用tree shaking、sideEffects等 - }, - react: { - runtime: 'automatic', - }, - typescript: { - isTSX: true, - jsxPragma: 'React', - allExtensions: true, - allowNamespaces: true, - }, - }, - decorators: { - legacy: false, - decoratorsBeforeExport: false, - }, - classProperties: { - loose: false, - }, - runtime: { - absoluteRuntime: npath.dirname( - require.resolve('@babel/runtime-corejs3/package.json'), - ), - version: require('@babel/runtime-corejs3/package.json').version, - corejs: false, - helpers: true, // 使用到@babel/runtime - regenerator: true, // 使用到@babel/runtime - useESModules: false, - }, - exclude: [/@babel[/|\\\\]runtime/, /core-js/], + framework: 'react', + ts: true, + useBuiltIns: false, }, ], ], - plugins: [ - [ - require('babel-plugin-transform-taroapi'), - { packageName: '@tarojs/taro', apis }, - ], // taro可以加,tree-shaking用 - ], }) } diff --git a/packages/vantui-demo/config/webpack/miniChain.js b/packages/vantui-demo/config/webpack/miniChain.js index da8891196..547d86926 100644 --- a/packages/vantui-demo/config/webpack/miniChain.js +++ b/packages/vantui-demo/config/webpack/miniChain.js @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-var-requires */ const npath = require('path') const MiniFixPlugin = require('@antmjs/plugin-mini-fix') -const apis = require('@tarojs/taro-h5/dist/taroApis') module.exports = function (chain) { chain.plugin('MiniFixPlugin').use(new MiniFixPlugin()) chain.module @@ -21,70 +20,25 @@ module.exports = function (chain) { (/node_modules/.test(filename) && !( /taro/.test(filename) && - !/tarojs[\\/](runtime|shared)/.test(filename) + !/tarojs[\\/](runtime|shared|plugin-platform)/.test(filename) )), ) // node_modules需要二次编译的在这里处理,taro相关的包不能加载polyfill chain.module .rule('compile-node-modules') - .test(/tarojs[\\/](runtime|shared)/i) + .test(/tarojs[\\/](runtime|shared|plugin-platform)/i) .use('taro-loader') .loader(require.resolve('babel-loader')) .options({ presets: [ [ - '@antmjs/babel-preset', + 'taro', { - presets: { - env: { - debug: false, - - /** - * false: 不处理polyfill,自己手动引入【全量】 - * usage: 按需加载 polyfill,且不需要手动引入【按需】 - * entry: 必须手动引入,但会根据设置的目标环境全量导入【按环境全量】 - * 注:在 Babel 7.4.0 之后的版本,Babel官方明确建议了不再使用 @babel/polyfill ,建议使用 core-js/stable 和 regenerator-runtime/runtime。本包已经安装了core-js、@babel/plugin-transform-runtime和@babel/runtime,所以选择false或者entry选项的只需要在主文件顶部引入core-js即可 - */ - useBuiltIns: false, - corejs: false, - modules: false, // 对es6的模块文件不做转译,以便使用tree shaking、sideEffects等 - }, - react: { - runtime: 'automatic', - }, - typescript: { - isTSX: true, - jsxPragma: 'React', - allExtensions: true, - allowNamespaces: true, - }, - }, - decorators: { - legacy: false, - decoratorsBeforeExport: false, - }, - classProperties: { - loose: false, - }, - runtime: { - absoluteRuntime: npath.dirname( - require.resolve('@babel/runtime-corejs3/package.json'), - ), - version: require('@babel/runtime-corejs3/package.json').version, - corejs: false, - helpers: true, // 使用到@babel/runtime - regenerator: true, // 使用到@babel/runtime - useESModules: false, - }, - exclude: [/@babel[/|\\\\]runtime/, /core-js/], + framework: 'react', + ts: true, + useBuiltIns: false, }, ], ], - plugins: [ - [ - require('babel-plugin-transform-taroapi'), - { packageName: '@tarojs/taro', apis }, - ], // taro可以加,tree-shaking用 - ], }) } diff --git a/packages/vantui-demo/package.json b/packages/vantui-demo/package.json index 04287b75a..922513065 100644 --- a/packages/vantui-demo/package.json +++ b/packages/vantui-demo/package.json @@ -160,6 +160,7 @@ "babel-loader": "^8.2.3", "babel-plugin-import": "^1.13.3", "babel-plugin-transform-taroapi": "3.4.1", + "babel-preset-taro": "^3.4.1", "cross-env": "^7.0.3", "eslint": "^7.30.0", "prettier": "^2.3.2", diff --git a/packages/vantui-demo/yarn.lock b/packages/vantui-demo/yarn.lock index aad6ecac4..851494180 100644 --- a/packages/vantui-demo/yarn.lock +++ b/packages/vantui-demo/yarn.lock @@ -3438,7 +3438,7 @@ babel-plugin-transform-taroapi@3.4.1: resolved "https://registry.npmmirror.com/babel-plugin-transform-taroapi/-/babel-plugin-transform-taroapi-3.4.1.tgz#7d5397bc546c5f7c34cd4bde1b9af740ef10225c" integrity sha512-ve+tOxgr/ZAw4pxqeTgOE1YJek8xHwxvGYb7UJV9B51s8Q2+tVSQGzDQ6LZqyR0l7XW8RAuWESaeK1V5+2oxNA== -babel-preset-taro@3.4.1: +babel-preset-taro@3.4.1, babel-preset-taro@^3.4.1: version "3.4.1" resolved "https://registry.npmmirror.com/babel-preset-taro/-/babel-preset-taro-3.4.1.tgz#6e71a3358c12d60ec1ae44eba3cd5fe678007c4f" integrity sha512-tJIT8FryN1AxdV0ed21zeYC3RlbyowPF2SbUY7K4TgCOWBF96b0jTFYn8XTLBCYNdyCemuqsm//HhKJIaD4kLw== @@ -8769,8 +8769,8 @@ lodash.truncate@^4.4.2: "lodash@4.6.1 || ^4.16.1", lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.3.0: version "4.17.21" - resolved "https://registry.nlark.com/lodash/download/lodash-4.17.21.tgz?cache=0&sync_timestamp=1624543041613&other_urls=https%3A%2F%2Fregistry.nlark.com%2Flodash%2Fdownload%2Flodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" - integrity sha1-Z5WRxWTDv/quhFTPCz3zcMPWkRw= + resolved "https://registry.npmmirror.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" + integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== log-symbols@^2.2.0: version "2.2.0" diff --git a/packages/vantui-doc/docs/home.md b/packages/vantui-doc/docs/home.md index ffe7891c0..a3de10dc8 100644 --- a/packages/vantui-doc/docs/home.md +++ b/packages/vantui-doc/docs/home.md @@ -94,5 +94,5 @@ ### 快速沟通群
- +
\ No newline at end of file