Skip to content
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(babel-preset): add react-refresh and vue 3 support #36

Merged
merged 4 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/big-badgers-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@1stg/babel-preset": minor
---

feat(babel-preset): add react-refresh and vue 3 support
12 changes: 12 additions & 0 deletions .changeset/early-kings-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@1stg/app-config": minor
"@1stg/babel-preset": minor
"@1stg/commitlint-config": minor
"@1stg/eslint-config": minor
"@1stg/lib-config": minor
"@1stg/lint-staged": minor
"@1stg/postcss-config": minor
"@1stg/stylelint-config": minor
---

chore: bump pkgr packages
5 changes: 5 additions & 0 deletions .changeset/tough-files-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@1stg/lib-config": major
---

feat: upgrade `@pkgr/rollup`, use `rollup-plugin-esbuild` by default
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@changesets/changelog-github": "^0.4.0",
"@changesets/cli": "^2.16.0",
"@types/jest": "^26.0.23",
"@types/node": "^15.9.0",
"@types/node": "^15.12.0",
"@types/react": "^17.0.9",
"@types/unist": "^2.0.3",
"core-js": "^3.13.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/app-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"@1stg/common-config": "^2.1.0",
"@1stg/postcss-config": "^2.0.1",
"@1stg/stylelint-config": "^2.0.0",
"@pkgr/es-modules": "^0.4.0",
"@pkgr/imagemin": "^0.6.0",
"@pkgr/es-modules": "^0.4.2",
"@pkgr/imagemin": "^1.0.1",
"browserslist": "^4.16.6",
"postcss": "^8.3.0",
"stylelint": "^13.13.1"
Expand Down
50 changes: 39 additions & 11 deletions packages/babel-preset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ module.exports = declare(
'@babel/transform-async-to-generator',
'@babel/transform-regenerator',
],
bugfixes: true,
corejs: {
version: 3,
version: '3.13',
proposals: true,
},
shippedProposals: true,
targets: esmodules
? {
esmodules,
Expand Down Expand Up @@ -120,7 +122,7 @@ module.exports = declare(
useRuntimeModule: true,
},
])
} else if (async === 'promises') {
} else if (async === 'promise' || async === 'promises') {
plugins.push(require('babel-plugin-transform-async-to-promises'))
}

Expand Down Expand Up @@ -150,14 +152,25 @@ module.exports = declare(
development: isDev,
},
]
const reactPlugin = isProd
? [
require('babel-plugin-transform-react-remove-prop-types'),
{
removeImport: true,
},
]
: isDev && tryRequirePkg('react-hot-loader/babel')

let reactPlugin

if (isProd) {
reactPlugin = [
require('babel-plugin-transform-react-remove-prop-types'),
{
removeImport: true,
},
]
} else if (isDev) {
const reactRefreshBabelPlugin = tryRequirePkg('react-refresh/babel')
reactPlugin =
react &&
(react.plugin === 'refresh' ||
(react.plugin == null && reactRefreshBabelPlugin))
? reactRefreshBabelPlugin
: tryRequirePkg('react-hot-loader/babel')
}

if (react) {
presets.push(reactPreset)
Expand All @@ -168,7 +181,22 @@ module.exports = declare(
}

if (vue) {
presets.push('@vue/babel-preset-jsx')
const vuePkg = tryRequirePkg('vue/package.json')
const majorVersion = +(
vue.version || (vue === true ? vuePkg && vuePkg.version : String(vue))
).split('.')[0]
if (majorVersion === 3) {
plugins.push([
require('@vue/babel-plugin-jsx'),
{
transformOn: true,
optimize: true,
...vue.options,
},
])
} else {
presets.push([require('@vue/babel-preset-jsx'), vue.options])
}
}

return {
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
"@babel/preset-env": "^7.14.4",
"@babel/preset-react": "^7.13.13",
"@babel/preset-typescript": "^7.13.0",
"@pkgr/utils": "^0.7.1",
"@pkgr/utils": "^1.0.1",
"@vue/babel-helper-vue-jsx-merge-props": "^1.2.1",
"@vue/babel-plugin-jsx": "^1.0.6",
"@vue/babel-preset-jsx": "^1.2.4",
"babel-plugin-import": "^1.13.3",
"babel-plugin-transform-async-to-promises": "^0.8.15",
Expand Down
2 changes: 1 addition & 1 deletion packages/commitlint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dependencies": {
"@commitlint/config-conventional": "^12.1.4",
"@commitlint/config-lerna-scopes": "^12.1.4",
"@pkgr/utils": "^0.7.1"
"@pkgr/utils": "^1.0.1"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@angular-eslint/template-parser": "^12.1.0",
"@babel/eslint-parser": "^7.14.4",
"@babel/eslint-plugin": "^7.13.16",
"@pkgr/utils": "^0.7.1",
"@pkgr/utils": "^1.0.1",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/eslint-plugin-tslint": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
Expand All @@ -42,7 +42,7 @@
"eslint-plugin-sonar": "^0.5.1",
"eslint-plugin-sonarjs": "^0.7.1-117",
"eslint-plugin-svelte": "^1.1.2",
"eslint-plugin-unicorn": "^33.0.0",
"eslint-plugin-unicorn": "^33.0.1",
"eslint-plugin-vue": "^7.10.0"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@1stg/common-config": "^2.0.0",
"@pkgr/rollup": "^0.12.1",
"@pkgr/rollup": "^1.0.2",
"jest": "^27.0.4"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/lint-staged/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@1stg/prettier-config": "^1.7.3",
"@pkgr/utils": "^0.7.1",
"@pkgr/utils": "^1.0.1",
"cross-env": "^7.0.3",
"prettier": "^2.3.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"cssnano": "^5.0.5",
"cssnano-preset-advanced": "^5.1.2",
"postcss-import": "^14.0.2",
"postcss-modules": "^4.0.0",
"postcss-modules": "^4.1.0",
"postcss-normalize": "^10.0.0",
"postcss-preset-env": "^6.7.0",
"postcss-url": "^10.1.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/stylelint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"stylelint": ">=13.0.0"
},
"dependencies": {
"@pkgr/utils": "^0.7.1",
"@pkgr/utils": "^1.0.1",
"stylelint-config-prettier": "^8.0.2",
"stylelint-config-standard": "^22.0.0",
"stylelint-high-performance-animation": "^1.5.2",
Expand Down
Loading