diff --git a/build.config.ts b/build.config.ts index f5f79c0..26fcf0f 100644 --- a/build.config.ts +++ b/build.config.ts @@ -1,9 +1,12 @@ - -export default { +import { defineBuildConfig } from "unbuild"; +export default defineBuildConfig({ entries: ["./src/index"], rollup: { emitCJS: true, + esbuild: { + minify: true, + }, }, externals: ['vite'], declaration: true, -}; \ No newline at end of file +}); \ No newline at end of file diff --git a/package.json b/package.json index b633257..620b59c 100644 --- a/package.json +++ b/package.json @@ -33,12 +33,17 @@ "url": "https://github.com/holy-two/vite-plugin-alias" }, "devDependencies": { + "@holy-two/vite-plugin-alias": "workspace:*", + "@rollup/plugin-commonjs": "^25.0.7", "typescript": "^5.3.3", "unbuild": "^2.0.0", "vite": "^5.0.12" }, + "peerDependencies": { + "vite": ">=4.0.0" + }, "dependencies": { "@types/node": "^20.11.9", - "strip-json-comments": "^5.0.1" + "jsonc-parser": "^3.2.1" } } \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2c8d4e6..d7a6b0a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,10 +11,16 @@ importers: '@types/node': specifier: ^20.11.9 version: 20.11.9 - strip-json-comments: - specifier: ^5.0.1 - version: 5.0.1 + jsonc-parser: + specifier: ^3.2.1 + version: 3.2.1 devDependencies: + '@holy-two/vite-plugin-alias': + specifier: workspace:* + version: 'link:' + '@rollup/plugin-commonjs': + specifier: ^25.0.7 + version: 25.0.7(rollup@3.29.4) typescript: specifier: ^5.3.3 version: 5.3.3 @@ -948,7 +954,7 @@ packages: dev: true /commondir@1.0.1: - resolution: {integrity: sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=} + resolution: {integrity: sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==} dev: true /computeds@0.0.1: @@ -1228,7 +1234,7 @@ packages: dev: true /fs.realpath@1.0.0: - resolution: {integrity: sha1-FQStJSMVjKpA20onh8sBQRmU6k8=} + resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==} dev: true /fsevents@2.3.3: @@ -1314,7 +1320,7 @@ packages: dev: true /inflight@1.0.6: - resolution: {integrity: sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=} + resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==} dependencies: once: 1.4.0 wrappy: 1.0.2 @@ -1388,7 +1394,6 @@ packages: /jsonc-parser@3.2.1: resolution: {integrity: sha512-AilxAyFOAcK5wA1+LeaySVBrHsGQvUFCDWXKpZjzaL0PqW+xfBOttn8GNtWKFWqneyMZj41MWF9Kl6iPWLwgOA==} - dev: true /jsonfile@6.1.0: resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==} @@ -1536,7 +1541,7 @@ packages: dev: true /once@1.4.0: - resolution: {integrity: sha1-WDsap3WWHUsROsF9nFC6753Xa9E=} + resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} dependencies: wrappy: 1.0.2 dev: true @@ -1986,11 +1991,6 @@ packages: resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==} engines: {node: '>=0.10.0'} - /strip-json-comments@5.0.1: - resolution: {integrity: sha512-0fk9zBqO67Nq5M/m45qHCJxylV/DhBlIOVExqgOMiCCrzrhU6tCibRXNqE3jwJLftzE9SNuZtYbpzcO+i9FiKw==} - engines: {node: '>=14.16'} - dev: false - /stylehacks@6.0.2(postcss@8.4.33): resolution: {integrity: sha512-00zvJGnCu64EpMjX8b5iCZ3us2Ptyw8+toEkb92VdmkEaRaSGBNKAoK6aWZckhXxmQP8zWiTaFaiMGIU8Ve8sg==} engines: {node: ^14 || ^16 || >=18.0} @@ -2197,7 +2197,7 @@ packages: typescript: 5.3.3 /wrappy@1.0.2: - resolution: {integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=} + resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} dev: true /yallist@3.1.1: diff --git a/src/index.ts b/src/index.ts index 61b227c..9305326 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import { Plugin } from 'vite'; import { join } from 'path'; import { existsSync, readFileSync } from 'fs'; -import stripJsonComments from 'strip-json-comments'; +import { parse } from 'jsonc-parser'; const alias = () => { const tsconfigPath = join(process.cwd(), 'tsconfig.json'); @@ -20,11 +20,11 @@ const alias = () => { } else { configStr = readFileSync(jsconfigPath, 'utf8'); }; - const tsConfig = JSON.parse(stripJsonComments(configStr.replace(/,\s*([\]}])/g, '$1'))); + const tsConfig = parse(configStr); const paths: TsConfigPaths = tsConfig?.compilerOptions?.paths; if (!paths) { - console.warn("tsconfig.json's paths or jsconfig.json's paths not found"); + console.error("tsconfig.json's paths or jsconfig.json's paths not found"); }; // todo: 未处理 tsconfig.json 中的 baseUrl