-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
三少
committed
Mar 14, 2023
1 parent
f9ce13f
commit 26e954c
Showing
7 changed files
with
45 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module.exports = function (chain) { | ||
// taro内部的配置:scriptRule.exclude = [filename => /css-loader/.test(filename) || (/node_modules/.test(filename) && !(/taro/.test(filename)))]; | ||
// 下面重写exclude的配置,部分三方包需要babel,包括taro、@antmjs等 | ||
// 根据exclude可以看出,千万不要在项目名称上面带上taro字样,否则所有引用到node_modules的包都会重新被编译一次 | ||
// 以下配置将不再使用usage配置,因为根据小程序官方描述,ios9开始基本都已支持了,浏览器可以使用polyfill.io 国内可以用阿里云版的,index.html有引用 | ||
|
||
/* | ||
* 如果babel.config.js设置useBuiltIns:usage | ||
* /tarojs[\\/](runtime|shared|plugin-platform|components)/.test(filename) 应该被exculde | ||
* /tarojs[\\/](runtime|shared|plugin-platform)/.test(filename) 应该单独babel 且设置useBuiltIns:false | ||
*/ | ||
chain.module | ||
.rule('script') | ||
.exclude.clear() | ||
.add( | ||
(filename) => | ||
/css-loader/.test(filename) || | ||
(/node_modules/.test(filename) && | ||
!/(taro)|(@antmjs)|(react-spring)|(recoil)|(buffer)|(qrcode)/.test( | ||
filename, | ||
)), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,8 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const H5FixPlugin = require('@antmjs/plugin-h5-fix') | ||
const commonChain = require('./commonChain') | ||
|
||
module.exports = function (chain) { | ||
chain.plugin('H5FixPlugin').use(new H5FixPlugin()) | ||
// taro内部的配置:scriptRule.exclude = [filename => /css-loader/.test(filename) || (/node_modules/.test(filename) && !(/taro/.test(filename)))]; | ||
// taro内置的webpack配置在编译script的时候使用的是项目根目录的babel.config.js的配置,如果你项目的useBuiltIns设置为'usage',则runtime和shared都会polyfill,就会导致出错 | ||
// 所以下面重写了exclude的配置,并给runtime和shared单独进行了匹配 | ||
// 根据exclude可以看出,千万不要在项目名称上面带上taro字样,否则所有引用到node_modules的包都会重新被编译一次 | ||
chain.module | ||
.rule('script') | ||
.exclude.clear() | ||
.add( | ||
(filename) => | ||
/css-loader/.test(filename) || | ||
(/node_modules/.test(filename) && | ||
!( | ||
/(taro)|(react-spring)|(@antmjs)|(recoil)|(buffer)|(qrcode)/.test( | ||
filename, | ||
) && !/tarojs[\\/](runtime|shared|plugin-platform)/.test(filename) | ||
)), | ||
) | ||
|
||
chain.module | ||
.rule('taro-script') | ||
.test(/tarojs[\\/](runtime|shared|plugin-platform)/i) | ||
.use('taro-loader') | ||
.loader(require.resolve('babel-loader')) | ||
.options({ | ||
presets: [ | ||
[ | ||
'taro', | ||
{ | ||
framework: 'react', | ||
ts: true, | ||
// 这里必须要用false即runtime和shared这两个包不能进行polyfill | ||
useBuiltIns: false, | ||
hot: false, | ||
}, | ||
], | ||
], | ||
}) | ||
commonChain(chain) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters