-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support browsersList #12874
Open
Jinbao1001
wants to merge
2
commits into
master
Choose a base branch
from
feat/browsersList
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: support browsersList #12874
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1477,6 +1477,8 @@ import SmileUrl, { ReactComponent as SvgSmile } from './smile.svg'; | |||||
- 默认值:`{ chrome: 80 }` | ||||||
|
||||||
配置需要兼容的浏览器最低版本。Umi 会根据这个自定引入 polyfill、配置 autoprefixer 和做语法转换等。 | ||||||
注意:如果`package.json` 中存在 `browsersList`, 或存在 `browsersList` 配置文件, `target` 设置默认失效. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
|
||||||
示例, | ||||||
|
||||||
|
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 | ||||
---|---|---|---|---|---|---|
|
@@ -4,13 +4,14 @@ import { | |||||
VIRTUAL_ENTRY_DIR, | ||||||
} from '@umijs/mfsu'; | ||||||
import { chalk, lodash, resolve } from '@umijs/utils'; | ||||||
import { warn } from '@umijs/utils/dist/logger'; | ||||||
import browsersList from 'browserslist'; | ||||||
import { dirname, isAbsolute } from 'path'; | ||||||
import { ProvidePlugin } from '../../compiled/webpack'; | ||||||
import Config from '../../compiled/webpack-5-chain'; | ||||||
import { MFSU_NAME } from '../constants'; | ||||||
import { Env, IConfig, Transpiler } from '../types'; | ||||||
import { es5ImcompatibleVersionsToPkg, isMatch } from '../utils/depMatch'; | ||||||
|
||||||
interface IOpts { | ||||||
config: Config; | ||||||
userConfig: IConfig; | ||||||
|
@@ -124,47 +125,54 @@ export async function addJavaScriptRules(opts: IOpts) { | |||||
|
||||||
// const prefix = existsSync(join(cwd, 'src')) ? join(cwd, 'src') : cwd; | ||||||
const srcTranspiler = userConfig.srcTranspiler || Transpiler.babel; | ||||||
const browsersListConfig = browsersList.loadConfig({ path: cwd }); | ||||||
const options: any = { | ||||||
// Tell babel to guess the type, instead assuming all files are modules | ||||||
// https://github.com/webpack/webpack/issues/4039#issuecomment-419284940 | ||||||
sourceType: 'unambiguous', | ||||||
babelrc: false, | ||||||
configFile: false, | ||||||
cacheDirectory: false, | ||||||
browserslistConfigFile: !!browsersListConfig, | ||||||
// process.env.BABEL_CACHE !== 'none' | ||||||
// ? join(cwd, `.umi/.cache/babel-loader`) | ||||||
// : false, | ||||||
// targets: userConfig.targets, | ||||||
// 解决 vue MFSU 解析 需要 | ||||||
customize: userConfig.babelLoaderCustomize, | ||||||
presets: [ | ||||||
opts.babelPreset || [ | ||||||
require.resolve('@umijs/babel-preset-umi'), | ||||||
{ | ||||||
presetEnv: {}, | ||||||
presetReact: {}, | ||||||
presetTypeScript: {}, | ||||||
pluginTransformRuntime: {}, | ||||||
pluginLockCoreJS: {}, | ||||||
pluginDynamicImportNode: false, | ||||||
pluginAutoCSSModules: userConfig.autoCSSModules, | ||||||
}, | ||||||
], | ||||||
...opts.extraBabelPresets, | ||||||
...(userConfig.extraBabelPresets || []).filter(Boolean), | ||||||
], | ||||||
plugins: [ | ||||||
useFastRefresh && require.resolve('react-refresh/babel'), | ||||||
...opts.extraBabelPlugins, | ||||||
...(userConfig.extraBabelPlugins || []), | ||||||
].filter(Boolean), | ||||||
}; | ||||||
if (!browsersListConfig) { | ||||||
options.targets = userConfig.targets; | ||||||
} else if (userConfig.targets) { | ||||||
warn('检测到项目中存在browsersList配置, targets 配置已失效'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 英文的是不是比较好? |
||||||
} | ||||||
srcRules.forEach((rule) => { | ||||||
if (srcTranspiler === Transpiler.babel) { | ||||||
rule | ||||||
.use('babel-loader') | ||||||
.loader(require.resolve('../../compiled/babel-loader')) | ||||||
.options({ | ||||||
// Tell babel to guess the type, instead assuming all files are modules | ||||||
// https://github.com/webpack/webpack/issues/4039#issuecomment-419284940 | ||||||
sourceType: 'unambiguous', | ||||||
babelrc: false, | ||||||
configFile: false, | ||||||
cacheDirectory: false, | ||||||
browserslistConfigFile: false, | ||||||
// process.env.BABEL_CACHE !== 'none' | ||||||
// ? join(cwd, `.umi/.cache/babel-loader`) | ||||||
// : false, | ||||||
targets: userConfig.targets, | ||||||
// 解决 vue MFSU 解析 需要 | ||||||
customize: userConfig.babelLoaderCustomize, | ||||||
presets: [ | ||||||
opts.babelPreset || [ | ||||||
require.resolve('@umijs/babel-preset-umi'), | ||||||
{ | ||||||
presetEnv: {}, | ||||||
presetReact: {}, | ||||||
presetTypeScript: {}, | ||||||
pluginTransformRuntime: {}, | ||||||
pluginLockCoreJS: {}, | ||||||
pluginDynamicImportNode: false, | ||||||
pluginAutoCSSModules: userConfig.autoCSSModules, | ||||||
}, | ||||||
], | ||||||
...opts.extraBabelPresets, | ||||||
...(userConfig.extraBabelPresets || []).filter(Boolean), | ||||||
], | ||||||
plugins: [ | ||||||
useFastRefresh && require.resolve('react-refresh/babel'), | ||||||
...opts.extraBabelPlugins, | ||||||
...(userConfig.extraBabelPlugins || []), | ||||||
].filter(Boolean), | ||||||
}); | ||||||
.options(options); | ||||||
} else if (srcTranspiler === Transpiler.swc) { | ||||||
rule | ||||||
.use('swc-loader') | ||||||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个会比较奇怪,用户不知道为啥 target 就不生效了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
会同时在控制台 warning.
这个是考虑遵循社区约定, 并且把
browsersList
置为优先级最高.并且
umi4
targets
配置由于历史原因, 本来就是不生效的, 这是一个bug
, 但是目前还未修复, 会影响到现有项目.