Skip to content

Commit

Permalink
fix: 升级taro
Browse files Browse the repository at this point in the history
  • Loading branch information
三少 committed Feb 14, 2022
1 parent 0e109a7 commit 7878f01
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 161 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@
### 快速沟通群

<div style="display:inline-block;">
<img style="width:300px" src="https://antm-js.gitee.io/resource/wechat_v16.jpeg" />
<img style="width:300px" src="https://antm-js.gitee.io/resource/wechat_v17.jpeg" />
</div>
55 changes: 4 additions & 51 deletions packages/vantui-demo/babel.config.js
Original file line number Diff line number Diff line change
@@ -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',
{
Expand Down
59 changes: 6 additions & 53 deletions packages/vantui-demo/config/webpack/h5Chain.js
Original file line number Diff line number Diff line change
@@ -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来处理
Expand All @@ -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用
],
})
}
58 changes: 6 additions & 52 deletions packages/vantui-demo/config/webpack/miniChain.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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用
],
})
}
1 change: 1 addition & 0 deletions packages/vantui-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/vantui-demo/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion packages/vantui-doc/docs/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@
### 快速沟通群

<div style="display:inline-block;">
<img style="width:300px" src="https://antm-js.gitee.io/resource/wechat_v16.jpeg" />
<img style="width:300px" src="https://antm-js.gitee.io/resource/wechat_v17.jpeg" />
</div>

0 comments on commit 7878f01

Please sign in to comment.