Web Analytics

unplugin-check-syntax

⭐ 1 stars Hindi by cklwblove

🌐 भाषा

unplugin-check-syntax

npm version

एक सामान्य सिंटैक्स जांच प्लगइन, जो कई बिल्ड टूल्स (Webpack, Vite, Rollup, esbuild, Rspack आदि) को सपोर्ट करता है, JavaScript और HTML फाइलों में ECMAScript सिंटैक्स कम्पैटिबिलिटी को जांचने के लिए। यह प्लगइन rsbuild-plugin-check-syntax से प्रेरित है।

फ़ीचर विशेषताएँ

इंस्टॉलेशन

npm install @winner-fed/unplugin-check-syntax --save-dev

उपयोग विधि

Vite

// vite.config.ts
import { defineConfig } from 'vite'
import checkSyntax from '@winner-fed/unplugin-check-syntax/vite'

export default defineConfig({ plugins: [ checkSyntax({ targets: ['> 1%', 'last 2 versions'], // 或者直接指定 ECMAScript 版本 // ecmaVersion: 'es2015' }), ], })

वेबपैक

// webpack.config.js
const checkSyntax = require('@winner-fed/unplugin-check-syntax/webpack')

module.exports = { plugins: [ checkSyntax({ targets: ['> 1%', 'last 2 versions'], }), ], }

रोलअप

// rollup.config.js
import checkSyntax from '@winner-fed/unplugin-check-syntax/rollup'

export default { plugins: [ checkSyntax({ targets: ['> 1%', 'last 2 versions'], }), ], }

एसबिल्ड

// esbuild.config.js
const { build } = require('esbuild')
const checkSyntax = require('@winner-fed/unplugin-check-syntax/esbuild')

build({ plugins: [ checkSyntax({ targets: ['> 1%', 'last 2 versions'], }), ], })

###Rspack

// rspack.config.js
const checkSyntax = require('@winner-fed/unplugin-check-syntax/rspack')

module.exports = { plugins: [ checkSyntax({ targets: ['> 1%', 'last 2 versions'], }), ], }

कॉन्फ़िगरेशन विकल्प

interface CheckSyntaxOptions {
  /
   
  • 目标浏览器范围,使用 browserslist 格式
*/ targets?: string[]; /
  • 直接指定 ECMAScript 版本(优先级高于 targets)
*/ ecmaVersion?: 'es3' | 'es5' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'latest'; /
  • 排除源文件检查,支持正则表达式
*/ exclude?: RegExp | RegExp[]; /
  • 排除输出文件检查,支持正则表达式
*/ excludeOutput?: RegExp | RegExp[]; /
  • 手动包含额外的 JS 或 HTML 文件进行语法检查
  • 支持文件路径(相对于项目根目录)或 glob 模式
*/ include?: string[]; /
  • 排除特定的错误日志类型
*/ excludeErrorLogs?: ('source' | 'output' | 'reason' | 'code')[]; }

उपयोग उदाहरण

मूल विन्यास

// 使用 browserslist 配置
checkSyntax({
  targets: ['> 1%', 'last 2 versions', 'not dead'],
})

// 直接指定 ECMAScript 版本 checkSyntax({ ecmaVersion: 'es2015', })

फ़ाइलें बाहर रखें

checkSyntax({
  targets: ['> 1%', 'last 2 versions'],
  // 排除 node_modules 和测试文件
  exclude: [/node_modules/, /\.test\.js$/],
  // 排除特定输出文件
  excludeOutput: [/vendor\.js$/],
})

अतिरिक्त फ़ाइलें शामिल करें

checkSyntax({
  targets: ['> 1%', 'last 2 versions'],
  // 手动包含额外的文件进行检查
  include: [
    'src/legacy//*.js',        // 包含 legacy 目录下的所有 JS 文件
    'public/scripts/app.js',     // 包含特定的公共脚本文件
    'docs//*.html',            // 包含文档中的 HTML 文件
    '/absolute/path/to/file.js'  // 支持绝对路径
  ],
})

कस्टम त्रुटि आउटपुट

checkSyntax({
  targets: ['> 1%', 'last 2 versions'],
  // 只显示错误原因,不显示代码片段
  excludeErrorLogs: ['code', 'output'],
})

माइग्रेशन गाइड

यदि आप @rsbuild/plugin-check-syntax से माइग्रेट कर रहे हैं:

- import { pluginCheckSyntax } from '@rsbuild/plugin-check-syntax'
+ import checkSyntax from '@winner-fed/unplugin-check-syntax/vite' // 或其他构建工具

export default defineConfig({ plugins: [

  • pluginCheckSyntax({
+ checkSyntax({ targets: ['> 1%', 'last 2 versions'], }), ], })

कार्य सिद्धांत

लाइसेंस

MIT License

योगदान

Issue और Pull Request सबमिट करने का स्वागत है!

--- Tranlated By Open Ai Tx | Last indexed: 2025-07-21 ---