-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): Separate the babel config as a preset library, set absolute …
…babel-runtime path
- Loading branch information
Showing
10 changed files
with
164 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@yueqing/babel-preset-react-app': minor | ||
'@yueqing/webpack': minor | ||
--- | ||
|
||
Separate the babel config as a preset library, set absolute babel-runtime path |
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,24 @@ | ||
# @yueqing/babel-preset-yueqing-app | ||
|
||
@yueqing/webpack is a babel preset for yueqing webpack | ||
|
||
## Usage | ||
|
||
**Install** | ||
|
||
```shell | ||
yarn add @yueqing/babel-preset-yueqing-app -D | ||
|
||
# or | ||
|
||
npm install @yueqing/babel-preset-yueqing-app -D | ||
``` | ||
|
||
**Babel config** | ||
|
||
```js | ||
// babel.config.js | ||
module.exports = () => ({ | ||
presets: [require.resolve('@yueqing/babel-preset-yueqing-app')] | ||
}) | ||
``` |
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,60 @@ | ||
/* eslint-disable global-require */ | ||
import path from 'path' | ||
|
||
const main = (/* api: any , opts = {} */) => ({ | ||
presets: [ | ||
[ | ||
require('@babel/preset-env').default, | ||
{ | ||
// 允许在入口点中导入 core.js ,并使用 browserlist 选择 polyfills | ||
useBuiltIns: 'entry', | ||
corejs: 3, | ||
exclude: ['transform-typeof-symbol'], | ||
}, | ||
], | ||
require('@babel/preset-typescript').default, | ||
[ | ||
require('@babel/preset-react').default, | ||
{ | ||
runtime: 'automatic', | ||
}, | ||
], | ||
], | ||
plugins: [ | ||
[ | ||
require('@babel/plugin-transform-runtime').default, | ||
{ | ||
helpers: true, | ||
corejs: false, | ||
version: require('@babel/runtime/package.json').version, | ||
regenerator: true, | ||
// 预先解析 @babel/runtime 的位置,避免 @babel/runtime 未安装在根依赖目录时找不到 | ||
absoluteRuntime: path.dirname( | ||
require.resolve('@babel/runtime/package.json'), | ||
), | ||
}, | ||
], | ||
[ | ||
// TC39 Proposals: 使用装饰器 @xxx,注意:默认是旧版本的提案 | ||
require('@babel/plugin-proposal-decorators').default, | ||
false, | ||
], | ||
[ | ||
// ES2022: 类属性 class Foo { name = 'foo'; static getName = ... } | ||
require('@babel/plugin-proposal-class-properties').default, | ||
{ loose: true }, | ||
], | ||
[ | ||
// ES2022: 私有属性 class Foo { #name = 'foo'; getName = () => this.#name } | ||
require('@babel/plugin-proposal-private-property-in-object').default, | ||
{ loose: true }, | ||
], | ||
[ | ||
// TC39 Proposals: 私有方法 | ||
require('@babel/plugin-proposal-private-methods').default, | ||
{ loose: true }, | ||
], | ||
].filter(Boolean), | ||
}) | ||
|
||
export default main |
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,35 @@ | ||
{ | ||
"name": "@yueqing/babel-preset-react-app", | ||
"version": "0.0.0", | ||
"description": "babel preset for yueqing webpack", | ||
"main": "./lib/index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/simonwong/yueqing.git", | ||
"directory": "packages/webpack" | ||
}, | ||
"author": "Simon <wsj_simon@163.com>", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"scripts": { | ||
"build": "rm -rf ./lib && tsc -p tsconfig.json", | ||
"test": "pnpm run build && echo \"run test\"" | ||
}, | ||
"dependencies": { | ||
"@babel/core": "^7.17.5", | ||
"@babel/plugin-proposal-class-properties": "^7.16.7", | ||
"@babel/plugin-proposal-decorators": "^7.17.2", | ||
"@babel/plugin-proposal-private-methods": "^7.16.11", | ||
"@babel/plugin-proposal-private-property-in-object": "^7.16.7", | ||
"@babel/plugin-transform-runtime": "^7.17.0", | ||
"@babel/preset-env": "^7.16.11", | ||
"@babel/preset-react": "^7.16.7", | ||
"@babel/preset-typescript": "^7.16.7", | ||
"@babel/runtime": "^7.17.2" | ||
} | ||
} |
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,13 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"outDir": "./lib", | ||
}, | ||
"include": [ | ||
"*.ts", | ||
], | ||
"exclude": [ | ||
"**/node_modules/**" | ||
] | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.