Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shaobeichen/babel-plugin-client-variable
Preventing client variables from reporting errors on the server is very useful in SSR. 防止客户端变量在服务端报错,在SSR里使用很有用。
https://github.com/shaobeichen/babel-plugin-client-variable
babel babel-plugin client server ssr variable variables
Last synced: about 1 month ago
JSON representation
Preventing client variables from reporting errors on the server is very useful in SSR. 防止客户端变量在服务端报错,在SSR里使用很有用。
- Host: GitHub
- URL: https://github.com/shaobeichen/babel-plugin-client-variable
- Owner: shaobeichen
- Created: 2024-08-01T06:33:40.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-08-13T04:09:17.000Z (6 months ago)
- Last Synced: 2024-12-21T20:19:46.972Z (about 1 month ago)
- Topics: babel, babel-plugin, client, server, ssr, variable, variables
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# babel-plugin-client-variable
## 安装
使用 npm 安装
```bash
npm install babel-plugin-client-variable -D
```## 使用
在 babel.config.js 中添加
```diff
+ const clientVariable = require('babel-plugin-client-variable');module.exports = {
+ plugins: [
+ clientVariable
+ ]
}
```## 使用后效果
使用前打包编译成
```js
function name1() {
const aaa = document.querySelector('body')
console.warn(aaa)
}name1()
```使用后打包编译成
```js
function name1() {
const aaa = process.client ? document.querySelector('body') : {}
console.warn(aaa)
}name1()
```