From 227465f5a6cc271bfc2d643366eff2899c090d32 Mon Sep 17 00:00:00 2001 From: viarotel Date: Wed, 23 Oct 2024 10:58:16 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E2=9E=96=20Remove=20unnecessary=20lang?= =?UTF-8?q?uage=20flags=20at=20build=20time?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- package.json | 3 ++- pnpm-lock.yaml | 12 ++++++++++++ src/helpers/index.js | 2 +- src/plugins/vue/index.js | 4 ++-- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index b219dea..3c6e880 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,5 @@ lerna-debug.log* # User node_modules *.local -dist \ No newline at end of file +dist +cleants.config.js \ No newline at end of file diff --git a/package.json b/package.json index 0d2ca0c..fc510d1 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "scripts": { "lint": "eslint .", "lint:fix": "eslint . --fix", - "dev": "unbuild && npx .", + "dev": "cross-env CLEANTS_CONFIG_DIR=../ unbuild && npx .", "build": "unbuild", "release": "changelogen --release --push && unbuild && npm publish", "prepare": "husky install" @@ -53,6 +53,7 @@ "devDependencies": { "@antfu/eslint-config": "^3.7.3", "changelogen": "^0.5.7", + "cross-env": "^7.0.3", "eslint": "^9.12.0", "husky": "^9.1.6", "unbuild": "latest" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b33c240..5858275 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,6 +36,9 @@ importers: changelogen: specifier: ^0.5.7 version: 0.5.7 + cross-env: + specifier: ^7.0.3 + version: 7.0.3 eslint: specifier: ^9.12.0 version: 9.12.0(jiti@2.3.3) @@ -1231,6 +1234,11 @@ packages: core-js-compat@3.38.1: resolution: {integrity: sha512-JRH6gfXxGmrzF3tZ57lFx97YARxCXPaMzPo6jELZhv88pBH5VXpQ+y0znKGlFnzuaihqhLbefxSJxWJMPtfDzw==} + cross-env@7.0.3: + resolution: {integrity: sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==} + engines: {node: '>=10.14', npm: '>=6', yarn: '>=1'} + hasBin: true + cross-spawn@7.0.3: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} @@ -4106,6 +4114,10 @@ snapshots: dependencies: browserslist: 4.24.0 + cross-env@7.0.3: + dependencies: + cross-spawn: 7.0.3 + cross-spawn@7.0.3: dependencies: path-key: 3.1.1 diff --git a/src/helpers/index.js b/src/helpers/index.js index 3985142..4366217 100755 --- a/src/helpers/index.js +++ b/src/helpers/index.js @@ -109,7 +109,7 @@ export function capitalizeFirstLetter(str) { * })(); */ export async function loadConfig(configFileName = 'cleants.config.js') { - const configFilePath = path.join(process.cwd(), configFileName) + const configFilePath = path.join(process.cwd(), process.env.CLEANTS_CONFIG_DIR || '', configFileName) try { // 检查配置文件是否存在 diff --git a/src/plugins/vue/index.js b/src/plugins/vue/index.js index d58ea45..e83b84e 100755 --- a/src/plugins/vue/index.js +++ b/src/plugins/vue/index.js @@ -16,14 +16,14 @@ export const vuePlugin = () => ({ const script = descriptor.scriptSetup || descriptor.script if (!script) { - return updateScriptAttrs(content, { lang: 'js' }) + return updateScriptAttrs(content, { lang: void 0 }) } const scriptContent = script.content const lang = script.lang || 'js' - const replaceLang = lang === 'tsx' ? 'jsx' : 'js' + const replaceLang = lang === 'tsx' ? 'jsx' : void 0 let processContent = ['ts', 'tsx'].includes(lang) ? `\n${ctx.transpileFile(scriptContent, `.${lang}`)}`