PageSourceSearch

https://jeremy-ho.vercel.app/assets/js/02e47311.7a413c91.js

js jeremy-ho.vercel.app collected 2026-10-03 07:10:49 UTC 25,080 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkcode_fictionist=self.webpackChunkcode_fictionist||[]).push([[3202],{17380:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>d,contentTitle:()=>t,default:()=>h,frontMatter:()=>c,metadata:()=>l,toc:()=>o});const l=JSON.parse('{"id":"notes/Web_Dev/Web_Talk/Package/env_aligner","title":"[Pkg] Env Aligner / npm \u5957\u4ef6\u958b\u767c","description":"env-aligner","source":"@site/docs/notes/Web_Dev/Web_Talk/Package/03-env_aligner.mdx","sourceDirName":"notes/Web_Dev/Web_Talk/Package","slug":"/notes/Web_Dev/Web_Talk/Package/env_aligner","permalink":"/docs/notes/Web_Dev/Web_Talk/Package/env_aligner","draft":false,"unlisted":false,"tags":[{"inline":true,"label":"npm","permalink":"/docs/tags/npm"},{"inline":true,"label":"package","permalink":"/docs/tags/package"},{"inline":true,"label":"env-aligner","permalink":"/docs/tags/env-aligner"}],"version":"current","lastUpdatedAt":1766374113000,"sidebarPosition":3,"frontMatter":{"title":"[Pkg] Env Aligner / npm \u5957\u4ef6\u958b\u767c","tags":["npm","package","env-aligner"],"keywords":["npm","package","env-aligner"]},"sidebar":"notes","previous":{"title":"[Pkg] Handsontable","permalink":"/docs/notes/Web_Dev/Web_Talk/Package/handsontable_vue"},"next":{"title":"\u524d\u7aef\u6e2c\u8a66\u76f8\u95dc","permalink":"/docs/category/\u524d\u7aef\u6e2c\u8a66\u76f8\u95dc"}}');var i=s(74848),r=s(28453);const c={title:"[Pkg] Env Aligner / npm \u5957\u4ef6\u958b\u767c",tags:["npm","package","env-aligner"],keywords:["npm","package","env-aligner"]},t=void 0,d={},o=[{value:"Env Aligner \u529f\u80fd\u4ecb\u7d39",id:"env-aligner-\u529f\u80fd\u4ecb\u7d39",level:2},{value:"Features",id:"features",level:3},{value:"Installation",id:"installation",level:3},{value:"CLI Options",id:"cli-options",level:3},{value:"Programmatic Usage (Optional)",id:"programmatic-usage-optional",level:3},{value:"\u767c\u5e03\u5957\u4ef6",id:"\u767c\u5e03\u5957\u4ef6",level:2},{value:"Step 1: \u7576\u7136\u662f\u5beb\u597d\u7a0b\u5f0f\u78bc\u5566",id:"step-1-\u7576\u7136\u662f\u5beb\u597d\u7a0b\u5f0f\u78bc\u5566",level:3},{value:"Step 2: \u6e96\u5099\u597d <code>package.json</code>",id:"step-2-\u6e96\u5099\u597d-packagejson",level:3},{value:"Step 3: \u5957\u4ef6\u6253\u5305 (Optional)",id:"step-3-\u5957\u4ef6\u6253\u5305-optional",level:3},{value:"Step 4: \u767c\u5e03\u5957\u4ef6",id:"step-4-\u767c\u5e03\u5957\u4ef6",level:3},{value:"\u79fb\u9664 npm \u4e0a\u5df2\u767c\u5e03\u7684\u5957\u4ef6\u7248\u672c",id:"\u79fb\u9664-npm-\u4e0a\u5df2\u767c\u5e03\u7684\u5957\u4ef6\u7248\u672c",level:3},{value:"\u5e6b\u81ea\u5df1\u7684 commit \u4e0a tags",id:"\u5e6b\u81ea\u5df1\u7684-commit-\u4e0a-tags",level:3},{value:"Reference",id:"reference",level:2}];function a(e){const n={a:"a",admonition:"admonition",blockquote:"blockquote",br:"br",code:"code",h2:"h2",h3:"h3",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.admonition,{type:"info",children:(0,i.jsx)(n.p,{children:(0,i.jsx)(n.a,{href:"https://www.npmjs.com/package/env-aligner",children:"env-aligner"})})}),"\n",(0,i.jsxs)(n.p,{children:["\u5148\u7c21\u4ecb\u4e00\u4e0b\u9019\u500b\u5957\u4ef6\u597d\u4e86\uff0cEnv Aligner \u4e3b\u8981\u662f\u7528\u4f86\u6aa2\u67e5 ",(0,i.jsx)(n.code,{children:".env"})," \u8ddf ",(0,i.jsx)(n.code,{children:".env.example"})," \u9019\u5169\u500b\u6a94\u6848\u7684\u74b0\u5883\u8b8a\u6578\u662f\u5426\u6709\u5c0d\u9f4a\uff0c\u9019\u6a23\u53ef\u4ee5\u907f\u514d\u5728\u958b\u767c\u6216\u662f\u90e8\u7f72\u6642\u56e0\u70ba\u74b0\u588b\u8b8a\u6578\u5c0d\u4e0d\u9f4a\u800c\u9020\u6210\u554f\u984c\u3002"]}),"\n",(0,i.jsxs)(n.p,{children:["\u505a\u9019\u500b\u5957\u4ef6\u7684\u8d77\u56e0\uff0c\u5c31\u50cf\u67d0\u696d\u754c\u524d\u8f29\u8aaa\u7684\u300c\u8edf\u9ad4\u7684\u958b\u767c\u90fd\u6e90\u81ea\u751f\u6d3b\u4e2d\u7684\u554f\u984c\u300d\uff0cEnv Aligner \u7684\u51fa\u73fe\u5176\u5be6\u662f\u4f86\u81ea\u516c\u53f8\u9700\u6c42\u4e00\u500b",(0,i.jsx)(n.strong,{children:"\u5de5\u5177"}),"\u5728\u524d\u7aef\u81ea\u5df1\u958b\u767c\u3001build \u6216\u662f CI/CD pipeline \u6642\u53ef\u4ee5\u6aa2\u67e5\u74b0\u5883\u8b8a\u6578\u662f\u5426\u6709\u9f4a\u5168\uff0c\u6c92\u6709\u9f4a\u5168\u7684\u8a71\u5c31\u5674\u500b\u932f\u8aa4\u4e26\u628a\u6d41\u7a0b\u7d42\u6b62\uff0c\u4f86\u505a\u5230\u74b0\u5883\u8b8a\u6578\u7684\u7c21\u6613\u628a\u63a7\u3002",(0,i.jsx)(n.br,{}
1),"\n","\u5728\u6211 survey \u7684\u904e\u7a0b\u88e1\uff0c\u5176\u5be6\u6709\u767c\u73fe\u4e0d\u5c11\u5957\u4ef6\u6709\u985e\u4f3c\u7684\u529f\u80fd\uff0c\u4f46\u7e3d\u5728\u4e00\u4e9b\u7d30\u679d\u672b\u7bc0\u4e0a\u8ddf\u6211\u7684\u9700\u6c42\u7a0d\u6709\u5dee\u7570\uff0c\u6c92\u6709\u8fa6\u6cd5\u9054\u5230 100% \u543b\u5408\uff0c\u9019\u5176\u5be6\u4e5f\u6b63\u5e38\uff0c\u4e00\u822c\u958b\u6e90\u6027\u5957\u4ef6\u901a\u5e38\u90fd\u662f\u958b\u767c\u8005\u70ba\u4e86\u56e0\u61c9\u81ea\u8eab\u67d0\u4e9b\u9700\u6c42\u800c\u958b\u767c\uff0c\u7136\u5f8c\u60f3\u8aaa\u505a\u90fd\u505a\u4e86\u5c31\u653e\u5230 npm \u4e0a\u8b93\u5927\u5bb6\u7528\u7528\u770b\uff0c\u800c\u6211\u7684\u9700\u6c42\u53ef\u80fd\u8ddf\u4ed6\u7684\u9700\u6c42\u4e0d\u4e00\u6a23\u4e5f\u662f\u5408\u60c5\u5408\u7406\u3002",(0,i.jsx)(n.br,{}),"\n","\u90a3\u70ba\u4e86\u9054\u5230 100% \u7684\u9700\u6c42\uff0c\u6211\u4e00\u958b\u59cb\u5beb\u4e86\u500b\u8173\u672c\uff0c\u78ba\u78ba\u5be6\u5be6\u5730 work \u4e86\uff0c\u4f46\u5982\u679c\u8981\u61c9\u7528\u5728\u5404\u5c08\u6848\u4e0a\uff0c\u4e0d\u592a\u53ef\u80fd\u4e00\u76f4 copy / paste \u9019\u500b\u8173\u672c\uff0c\u90a3\u662f\u5426\u61c9\u8a72\u505a\u4e00\u500b\u65b0\u7684\u5957\u4ef6\u5462\uff1f\u65bc\u662f Env Aligner \u56e0\u61c9\u800c\u51fa\u3002"]}),"\n",(0,i.jsx)(n.p,{children:"\u9019\u7bc7\u6703\u5148\u7c21\u4ecb\u4e00\u4e0b Env Aligner \u7684\u529f\u80fd\uff0c\u4f46\u5176\u5be6\u91cd\u9ede\u662f\u5f8c\u65b9\u7ae0\u7bc0\u600e\u9ebc\u7c21\u6613\u5730\u88fd\u4f5c\u5957\u4ef6\u4e26\u767c\u5e03\u5230 npm \u4e0a\u3002"}),"\n",(0,i.jsx)(n.h2,{id:"env-aligner-\u529f\u80fd\u4ecb\u7d39",children:"Env Aligner \u529f\u80fd\u4ecb\u7d39"}),"\n",(0,i.jsx)(n.h3,{id:"features",children:"Features"}),"\n",(0,i.jsx)(n.p,{children:"Env Aligner \u4e3b\u8981\u6709\u4e94\u500b\u529f\u80fd\uff1a"}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsxs)(n.li,{children:["\u53c3\u7167 ",(0,i.jsx)(n.code,{children:".env.example"})," \u6aa2\u67e5 ",(0,i.jsx)(n.code,{children:".env"})," \u6a94\u6848\u4e2d\u662f\u5426\u6709\u7f3a\u5c11\u7684\u8b8a\u6578\u3002"]}),"\n",(0,i.jsxs)(n.li,{children:["\u53c3\u7167 ",(0,i.jsx)(n.code,{children:".env.example"})," \u6aa2\u67e5 ",(0,i.jsx)(n.code,{children:".env"})," \u6a94\u6848\u4e2d\u662f\u5426\u6709\u7a7a\u503c\u7684\u8b8a\u6578\u3002"]}),"\n",(0,i.jsxs)(n.li,{children:["\u53c3\u7167 ",(0,i.jsx)(n.code,{children:".env.example"})," \u6aa2\u67e5 ",(0,i.jsx)(n.code,{children:".env"})," \u6a94\u6848\u4e2d\u662f\u5426\u6709\u591a\u9918\u7684\u8b8a\u6578\u3002(strict \u6a21\u5f0f\u9650\u5b9a)"]}),"\n",(0,i.jsxs)(n.li,{children:["\u53c3\u7167 ",(0,i.jsx)(n.code,{children:".env.example"})," \u81ea\u52d5\u5c0d\u9f4a ",(0,i.jsx)(n.code,{children:".env"})," \u6a94\u6848\u4e2d\u7684\u8b8a\u6578\u3002\u6b64\u9805\u6703\u79fb\u9664\u4f7f\u7528\u8005\u5728 ",(0,i.jsx)(n.code,{children:".env"})," \u6a94\u6848\u4e2d\u591a\u51fa\u7684\u8a3b\u89e3\u4ee5\u53ca\u8b8a\u6578\uff0c\u4f46\u6703\u4fdd\u7559\u4f7f\u7528\u8005\u5df2\u7d93\u586b\u5165\u8b8a\u6578\u7684\u503c\u3002(strict \u6a21\u5f0f\u9650\u5b9a)"]}),"\n",(0,i.jsxs)(n.li,{children:["\u53c3\u7167 ",(0,i.jsx)(n.code,{children:".env.example"})," \u81ea\u52d5\u7522\u751f\u4e00\u4efd ",(0,i.jsx)(n.code,{children:".env"})," \u6a94\u6848\uff0c\u5c31\u4e0d\u7528\u624b\u52d5 copy / paste\u3002"]}),"\n"]}),"\n",(0,i.jsx)(n.h3,{id:"installation",children:"Installation"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-powershell",children:"npm install env-aligner\n"})}),"\n",(0,i.jsx)(n.h3,{id:"cli-options",children:"CLI Options"}),"\n",(0,i.jsxs)(n.table,{children:[(0,i.jsx)(n.thead,{children:(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.th,{children:"Option"}),(0,i.jsx)(n.th,{children:"Description"}),(0,i.jsx)(n.th,{children:"Default"})]})}),(0,i.jsxs)(n.tbody,{children:[(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"--dir"})}),(0,i.jsx)(n.td,{children:"Root directory to scan."}),(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"process.cwd()"})})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"--schema"})}),(0,i.jsxs)(n.td,{children:["Schema file name (usually ",(0,i.jsx)(n.code,{children:".env.example"}),")."]}),(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:".env.example"})})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"--env"})}),(0,i.jsx)(n.td,{children:"Env file name to validate or align."}),(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:".env"})})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"--strict"})}),(0,i.jsxs)(n.td,{children:["Enable strict mode: warns about extra keys in ",(0,i.jsx)(n.code,{children:".env"})," not in the schema."]}),(0,i.jsx)(n.td,{children:"Not enabled (unless flag is present)"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"--align"})}),(0,i.jsxs)(n.td,{children:["Enable align mode: auto-fix ",(0,i.jsx)(n.code,{children:".env"})," format based on schema. \u26a0\ufe0f Only works with ",(0,i.jsx)(n.code,{children:"--strict"}),"."]}),(0,i.jsx)(n.td,{children:"Not enabled (unless flag is present)"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"--clone"})}),(0,i.jsx)(n.td,{children:"Clone schema to env file if env does not exist in the folder."}),(0,i.jsx)(n.td,{children:"Not enabled (unless flag is present)"})]})]})]}),"\n",(0,i.jsxs)(n.blockquote,{children:["\n",(0,i.jsx)(n.p,{children:"Examples:"}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{children:"npx env-aligner\nnpx env-aligner --dir .devcontainer --schema config.example --env config.env\nnpx env-aligner --clone\nnpx env-aligner --strict --align\n"})}),"\n",(0,i.jsx)(n.h3,{id:"programmatic-usage-optional",children:"Programmatic Usage (Optional)"}),"\n",(0,i.jsx)(n.p,{children:"\u96d6\u7136 Env Aligner \u672c\u610f\u4e0a\u662f\u505a\u6210\u4e3b\u8981\u4f7f\u7528 CLI\uff0c\u4f46\u5176\u5be6\u9084\u662f\u6709\u652f\u63f4\u518d JavaScript \u4e2d\u4f7f\u7528\u3002\u7576\u7136\uff0c\u6211\u9810\u60f3\u6703\u9019\u6a23\u7528\u7684\u4eba\u4e0d\u591a\u3002"}),"\n",(0,i.jsx)(n.admonition,{type:"warning",children:(0,i.jsxs)(n.p,{children:["\u56e0\u70ba Env Aligner \u958b\u767c\u4e4b\u521d\u5e0c\u671b\u5b83\u80fd\u652f\u63f4\u5927\u90e8\u5206\u5c08\u6848\uff0c\u4e0d\u8ad6\u65b0\u820a\uff0c\u6240\u4ee5\u5b83\u662f\u7528 CommonJS \u958b\u767c\u7684\uff0c\u9019\u6a23\u53ef\u4ee5\u78ba\u4fdd\u5728\u5927\u90e8\u5206 Node.js \u74b0\u5883\u4e2d\u90fd\u80fd\u904b\u4f5c\u3002",(0,i.jsx)(n.br,{}),"\n","\u5982\u679c\u5c08\u6848\u4e0a\u662f\u4f7f\u7528 ESM (\u73fe\u4eca\u5927\u90e8\u5206\u5c08\u6848\u90fd\u662f)\uff0c\u90a3\u5efa\u8b70\u5728\u4f7f\u7528\u6642\u662f\u653e\u5728 ",(0,i.jsx)(n.code,{children:"cjs"})," \u8173\u672c\u4e2d\u3002",(0,i.jsx)(n.br,{}),"\n","\u4f46\u6211\u4e00\u6982\u63a8\u85a6\u4f7f\u7528 CLI\u3002"]})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-js",metastring:'title="check-env.cjs"',children:"const envAligner = require('env-aligner')\n\nenvAligner({\n  rootDir: string, // Root directory to scan (default: process.cwd())\n  fileNames: {\n    schemaName: string, // Schema file name (e.g., '.env.example')\n    envName: string     // Env file name to validate (e.g., '.env')\n  },\n  mode: {\n    isStrict: boolean,  // Enable strict mode (extra key detection)\n    isAlign: boolean    // Enable align mode (auto format fix)\n  },\n  isClone: boolean       // Whether to generate the env file if missing\n})\n"})}),"\n",(0,i.jsx)(n.h2,{id:"\u767c\u5e03\u5957\u4ef6",children:"\u767c\u5e03\u5957\u4ef6"}),"\n",(0,i.jsxs)(n.p,{children:["\u5176\u5be6\u767c\u5e03\u5957\u4ef6\u6bd4\u60f3\u50cf\u4e2d\u66f4\u7c21\u55ae\uff0c\u6211\u662f\u770b\u8457 PJ \u8001\u5e2b\u7684\u90e8\u843d\u683c\u4e00\u6b65\u4e00\u6b65\u767c\u5e03\u7684\uff0c\u6c2e\u9
1019\u88e1\u6c92\u505a\u5230\u81ea\u52d5\u5316\u5566\uff0c\u56e0\u70ba\u9019\u73a9\u610f\u5152\u61c9\u8a72\u4e0d\u6703\u6709\u5f88\u591a\u66f4\u65b0~",(0,i.jsx)(n.br,{}),"\n","\u7136\u5f8c\u5728\u958b\u59cb\u524d\uff0c\u53ef\u4ee5\u5148\u53bb ",(0,i.jsx)(n.a,{href:"https://www.npmjs.com/",children:"npm"})," \u8a3b\u518a\u4e00\u500b\u5e33\u865f\uff0c\u7136\u5f8c\u5728\u7d42\u7aef\u6a5f\u4e2d\u767b\u5165\uff1a"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-powershell",children:"npm login\n"})}),"\n",(0,i.jsx)(n.h3,{id:"step-1-\u7576\u7136\u662f\u5beb\u597d\u7a0b\u5f0f\u78bc\u5566",children:"Step 1: \u7576\u7136\u662f\u5beb\u597d\u7a0b\u5f0f\u78bc\u5566"}),"\n",(0,i.jsxs)(n.p,{children:["\u9019\u6c92\u4ec0\u9ebc\u597d\u8aaa\u7684\uff0c\u5c31\u662f\u628a\u4f60\u7684\u7a0b\u5f0f\u78bc\u5beb\u597d\uff0c\u7136\u5f8c\u78ba\u4fdd\u5b83\u53ef\u4ee5\u6b63\u5e38\u904b\u4f5c\u3002",(0,i.jsx)(n.br,{}),"\n","\u4f46\u9019\u88e1\u6211\u8e29\u5230\u4e00\u500b\u5751\uff0c\u5c31\u662f CommonJS \u8ddf ES module \u7cfb\u7d71\u7684\u554f\u984c\u3002\u96d6\u8aaa esm \u662f\u73fe\u5728\u7684\u8da8\u52e2\uff0c\u4f46\u4e0d\u5f97\u4e0d\u8aaa cjs \u9084\u662f\u5f88\u591a\u7cfb\u7d71\u7684\u6a19\u6e96\uff0c\u6bd4\u5982 node.js\u3002",(0,i.jsx)(n.br,{}),"\n","\u6211\u4e00\u958b\u59cb\u7528 esm \u958b\u767c\uff0c\u7136\u5f8c\u5f8c\u4f86\u9047\u5230 node.js \u7121\u6cd5\u8dd1 esm \u7684\u554f\u984c\uff0c\u6240\u4ee5\u53c8\u82b1\u4e86\u4e00\u665a\u4e0a\u628a\u7a0b\u5f0f\u78bc\u6539\u56de cjs\uff0c\u6240\u4ee5\u958b\u767c\u6642\u8981\u60f3\u597d\u5957\u4ef6\u76ee\u6a19\u662f\u8981\u5728\u54ea\u4e9b\u7cfb\u7d71\u4e0a\u904b\u4f5c\u3002"]}),"\n",(0,i.jsx)(n.admonition,{type:"info",children:(0,i.jsxs)(n.p,{children:["cjs \u8ddf esm \u6700\u5927\u7684\u5dee\u7570\u5728 cjs \u4f7f\u7528 ",(0,i.jsx)(n.code,{children:"require"})," \u8ddf ",(0,i.jsx)(n.code,{children:"module.exports"}),"\uff0c\u800c esm \u4f7f\u7528 ",(0,i.jsx)(n.code,{children:"import"})," \u8ddf ",(0,i.jsx)(n.code,{children:"export"}),"\u3002",(0,i.jsx)(n.br,{}),"\n","\u9019\u5f0f\u958b\u767c\u6642\u6700\u5bb9\u6613\u78b0\u5230\u7684\u554f\u984c\u3002"]})}),"\n",(0,i.jsxs)(n.h3,{id:"step-2-\u6e96\u5099\u597d-packagejson",children:["Step 2: \u6e96\u5099\u597d ",(0,i.jsx)(n.code,{children:"package.json"})]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{\n  "name": "env-aligner", // \u9019\u88e1\u662f\u5957\u4ef6\u540d\u7a31\n  "version": "1.0.0-beta.2", // \u9019\u88e1\u662f\u5957\u4ef6\u7248\u672c\u865f\n  "description": "A developer-friendly tool.", // \u9019\u88e1\u53ef\u4ee5\u5beb\u5957\u4ef6\u7684\u63cf\u8ff0\n  "keywords": [ // \u9019\u88e1\u53ef\u4ee5\u6307\u5b9a\u95dc\u9375\u5b57\n    ".env",\n    ".env.example",\n    "dotenv",\n    "environment variables",\n    "check",\n    "align"\n  ],\n  "homepage": "https://github.com/ChungYingHo/env-aligner", // \u9019\u88e1\u53ef\u4ee5\u6307\u5b9a\u5957\u4ef6\u7684\u9996\u9801 (\u5982\u679c\u4f60\u6709\u55ae\u7368\u505a\u4ecb\u7d39\u7684\u7db2\u9801\u4e0d\u7136\u5c31\u653e github \u4e5f\u884c)\n  "bugs": { // \u9019\u88e1\u53ef\u4ee5\u6307\u5b9a bug \u56de\u5831\u7684\u4f4d\u7f6e\n    "url": "https://github.com/ChungYingHo/env-aligner/issues"\n  },\n  "repository": { // \u9019\u88e1\u53ef\u4ee5\u6307\u5b9a\u5957\u4ef6\u7684 git \u4f4d\u7f6e\n    "type": "git",\n    "url": "https://github.com/ChungYingHo/env-aligner.git"\n  },\n  "contributors": [ // \u9019\u88e1\u53ef\u4ee5\u5217\u51fa\u8ca2\u737b\u8005\n    "Jeremy Ho <[email protected]>(https://codefictionist.com/)",\n    "MJC <*****@gmail.com>(https://github.com/*****)"\n  ],\n  "license": "MIT", // \u9019\u88e1\u53ef\u4ee5\u6307\u5b9a\u6388\u6b0a\u65b9\u5f0f\n  "main": "dist/index.min.js", // \u9019\u88e1\u662f\u6307\u5b9a\u4e3b\u8981\u7684\u7a0b\u5f0f\u78bc\u8def\u5f91\n  "bin": {\n    "env-aligner": "dist/cli.min.js" // \u9019\u88e1\u662f\u6307\u5b9a CLI \u6307\u4ee4\u7684\u8def\u5f91\n  },\n  "scripts": {\n    "test": "echo \\"Error: no test specified\\" && exit 1",\n    "dev": "rollup -c -w",\n    "build": "rmdir /s /q dist && rollup -c"\n  }
1,\n  "dependencies": {\n    // \u9019\u500b\u4e0d\u7528\u89e3\u91cb\u5427\n  },\n  "devDependencies": {\n    // \u9019\u500b\u4e5f\u4e0d\u7528\u89e3\u91cb\u5427\n  },\n  "files": [\n    "dist" // \u9019\u88e1\u53ef\u4ee5\u6307\u5b9a\u8981\u767c\u5e03\u7684\u6a94\u6848\u8def\u5f91\n  ],\n  "engines": {\n    "node": ">=18.0.0" // \u9019\u88e1\u53ef\u4ee5\u6307\u5b9a\u8981\u5b89\u88dd\u9019\u500b\u5957\u4ef6\u9700\u6eff\u8db3\u7684 node.js \u7248\u672c\n  }\n}\n'})}),"\n",(0,i.jsx)(n.h3,{id:"step-3-\u5957\u4ef6\u6253\u5305-optional",children:"Step 3: \u5957\u4ef6\u6253\u5305 (Optional)"}),"\n",(0,i.jsxs)(n.p,{children:["\u5176\u5be6\u5982\u679c\u50cf\u662f\u6211\u53ea\u8f38\u51fa\u4e00\u500b js \u6a94\u6848\u7684\u8a71\uff0c\u9019\u6b65\u9a5f\u53ef\u4ee5\u7701\u7565\uff0c\u4f46\u5982\u679c\u5957\u4ef6\u5f88\u5927\u7684\u8a71\uff0c\u901a\u5e38\u9084\u662f\u6703\u6253\u5305\u4e00\u4e0b\uff0c\u9019\u6a23\u53ef\u4ee5\u6e1b\u5c11\u6a94\u6848\u5927\u5c0f\u3002",(0,i.jsx)(n.br,{}),"\n","\u5957\u4ef6\u6253\u5305\u901a\u5e38\u7528 ",(0,i.jsx)(n.strong,{children:"rollup"}),"\uff0c\u6211\u53bb\u4e86\u89e3\u4e86\u4e00\u4e0b\u5f8c\uff0c\u6703\u8f03\u5c11\u7528 webpack \u662f\u56e0\u70ba rollup \u8f03\u9069\u5408\u6253\u5305 library\u3002"]}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsx)(n.li,{children:"\u5b89\u88dd rollup"}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-powershell",children:"npm install rollup -D\n"})}),"\n",(0,i.jsxs)(n.ol,{start:"2",children:["\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"\u5b89\u88dd\u4e00\u4e9b rollup \u7684 plugin"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"rollup-plugin-terser\uff1a\u58d3\u7e2e js \u6a94\u6848"}),"\n",(0,i.jsx)(n.li,{children:"@rollup/plugin-json\uff1a\u8b80\u53d6 json \u6a94\u6848"}),"\n",(0,i.jsx)(n.li,{children:"@rollup/plugin-commonjs\uff1a\u8b80\u53d6 commonjs \u6a94\u6848"}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsxs)(n.p,{children:["\u5efa\u7acb\u4e00\u500b ",(0,i.jsx)(n.code,{children:"rollup.config.js"})," \u6a94\u6848"]}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-js",children:"const { terser } = require('rollup-plugin-terser')\nconst commonjs = require('@rollup/plugin-commonjs')\nconst json = require('@rollup/plugin-json')\n\nmodule.exports = [\n  {\n    input: 'src/lib/index.js', // \u5f15\u7528\u7684\u6a94\u6848\n    output: {\n      file: 'dist/index.min.js', // \u8f38\u51fa\u7684\u6a94\u6848\u8def\u5f91\u8207\u540d\u7a31\n      format: 'cjs', // \u8f38\u51fa\u7684\u683c\u5f0f\n      sourcemap: true, // \u662f\u5426\u7522\u751f sourcemap\n      exports: 'default' // \u8f38\u51fa\u7684\u65b9\u5f0f\uff0c\u9019\u500b\u8ddf cjs \u4ee5\u53ca esm \u6709\u95dc\n    },\n    plugins: [ // \u4f7f\u7528\u7684 plugin\n      terser(),\n      commonjs()\n    ],\n    external: ['dotenv', 'chalk', 'fs', 'path'] // \u9019\u88e1\u662f\u6307\u5b9a\u5916\u90e8\u5957\u4ef6\uff0c\u9019\u6a23 rollup \u5c31\u4e0d\u6703\u628a\u9019\u4e9b\u5957\u4ef6\u6253\u5305\u9032\u53bb\n  },\n  { // \u4ee5\u4e0b\u540c\u7406\uff0c\u9019\u53ea\u662f\u6253\u5305 CLI \u6307\u4ee4\u7684\u90e8\u5206\n    input: 'src/bin/cli.js',\n    output: {\n      file: 'dist/cli.min.js',\n      format: 'cjs',\n      sourcemap: true,\n      exports: 'default',\n      banner: '#!/usr/bin/env node'\n    },\n    plugins: [\n      terser(),\n      commonjs(),\n      json()\n    ],\n    external: ['dotenv', 'chalk', 'fs', 'path', 'commander']\n  }\n]\n"})}),"\n",(0,i.jsxs)(n.ol,{start:"4",children:["\n",(0,i.jsx)(n.li,{children:"\u6700\u5f8c\u57f7\u884c\u6253\u5305\u6307\u4ee4\uff1a"}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-powershell",children:"npm run build\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"info",children:(0,i.jsxs)(n.p,{children:["\u5176\u5be6 rollup \u5c0d esm \u7a0d\u5fae\u53cb\u5584\u4e00\u4e9b\uff0c\u4f46\u662f\u5c0d cjs \u4e5f\u662f\u53ef\u4ee5\u7684\uff0c\u53ea\u662f\u8981\u6ce8\u610f\u4e00\u4e9b\u984d\u5916\u8a2d\u5b9a\uff0c\u5982 ",(0,i.jsx)(n.code,{children:"exports"}),"\u3002",(0,i.jsx)(n.br,{}),"\n","\u4f46\u5176\u5be6\u5982\u679c\u771f\u7684\u6709\u932f\u8aa4\u4e4b\u985e\u7684\uff0crollup \u9084\u662f\u5f88\u8cbc\u5fc3\u5730\u6703\u63d0\u793a\u4f60\u8a72\u600e\u9ebc\u6539\u7684\u3002"]})}),"\n",(0,i.jsx)(n.h3,{id:"step-4-\u767c\u5e03\u5957\u4ef6",children:"Step 4: \u767c\u5e03\u5957\u4ef6"}),"\n",(0,i.jsx)(n.p,{children:"\u767c\u5e03\u5957\u4ef6\u6709\u5206 beta \u
16216\u6b63\u5f0f\u7248\uff0c\u6307\u4ee4\u4e5f\u6703\u7565\u6709\u4e0d\u540c\uff1a"}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsx)(n.li,{children:"\u767c\u5e03 beta \u7248"}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-powershell",children:"npm publish --tag beta\n"})}),"\n",(0,i.jsxs)(n.ol,{start:"2",children:["\n",(0,i.jsx)(n.li,{children:"\u767c\u5e03\u6b63\u5f0f\u7248"}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-powershell",children:"npm publish\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"warning",children:(0,i.jsxs)(n.p,{children:["\u5047\u8a2d\u5df2\u7d93\u767c\u5e03\u4e86\u5169\u500b beta \u7248\uff0c\u9019\u6642\u6703\u767c\u73fe\u600e\u9ebc\u7b2c\u4e00\u500b beta \u7248\u6a19\u7c64\u8b8a latest \u4e86\uff1f",(0,i.jsx)(n.br,{}),"\n","\u9019\u662f\u56e0\u70ba npm \u898f\u5b9a\u6709\u8907\u6578\u7248\u672c\u6642\uff0c\u81f3\u5c11\u8981\u6709\u4e00\u500b latest \u7248\u672c\u3002"]})}),"\n",(0,i.jsx)(n.h3,{id:"\u79fb\u9664-npm-\u4e0a\u5df2\u767c\u5e03\u7684\u5957\u4ef6\u7248\u672c",children:"\u79fb\u9664 npm \u4e0a\u5df2\u767c\u5e03\u7684\u5957\u4ef6\u7248\u672c"}),"\n",(0,i.jsx)(n.p,{children:"\u9019\u7528\u5728\u6709\u6642\u70ba\u4e86\u6e2c\u8a66\u5957\u4ef6\u7a69\u5b9a\u6027\u6703\u512a\u5148\u767c\u5e03 beta \u7248\u672c\uff0c\u4f46\u70ba\u4e86 debug\uff0cbeta \u7248\u53ef\u80fd\u6703\u6e90\u6e90\u4e0d\u7d55\u5730\u589e\u751f\uff0c\u9019\u6642\u5c31\u9700\u8981\u9069\u6642\u79fb\u9664 npm \u4e0a\u90a3\u4e9b\u5df2\u767c\u5e03\u7684\u7248\u672c\u3002"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-powershell",children:"npm unpublish [email protected] --force\n"})}),"\n",(0,i.jsx)(n.h3,{id:"\u5e6b\u81ea\u5df1\u7684-commit-\u4e0a-tags",children:"\u5e6b\u81ea\u5df1\u7684 commit \u4e0a tags"}),"\n",(0,i.jsxs)(n.p,{children:["\u9019\u9805\u4e0d\u662f\u5fc5\u505a\uff0c\u4f46\u5982\u679c\u5957\u4ef6\u662f\u6253\u7b97\u6301\u7e8c\u66f4\u65b0\u7684\uff0c\u90a3\u96e3\u514d\u6703\u9700\u8981\u5beb Changelog\u3002",(0,i.jsx)(n.br,{}),"\n","\u4e00\u822c\u5beb Changelog \u90fd\u6703\u653e\u500b github \u4e0a\u5169\u500b\u7248\u672c\u4e4b\u9593\u7684 diff\uff0c\u90a3\u9ebc\u5c31\u9700\u8981\u5728 commit \u4e0a\u52a0\u4e0a tags\uff0c\u9019\u6a23\u624d\u80fd\u5728 github \u4e0a\u770b\u5230\u5169\u500b\u7248\u672c\u4e4b\u9593\u7684\u5dee\u7570\u3002"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-powershell",children:'git tag -a v1.0.0 <commit-hash> -m "Release v1.0.0"\ngit push origin v1.0.0\n'})}),"\n",(0,i.jsx)(n.p,{children:"\u5982\u679c\u9700\u8981 tag \u7684\u5c31\u662f\u525b\u525b\u6700\u65b0\u7684 commit \uff0c\u53ef\u4ee5\u76f4\u63a5\u5beb\uff1a"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-powershell",children:'git tag -a v1.0.0 -m "Release v1.0.0"\n'})}),"\n",(0,i.jsx)(n.p,{children:"\u4e4b\u5f8c\u6709 v2.0.0 \u6642\uff0c\u540c\u6a23\u4e0a\u5b8c tag \u5c31\u53ef\u4ee5\u4f9d\u4e0b\u9762\u65b9\u5f0f\u770b\u7248\u672c\u9593\u7684 diff\uff1a"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{children:"https://github.com/\u4f60\u7684\u5e33\u865f/\u4f60\u7684\u5c08\u6848/compare/v1.0.0...v2.0.0\n"})}),"\n",(0,i.jsx)(n.h2,{id:"reference",children:"Reference"}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"https://pjchender.dev/devops/devops-publish-npm-0/",children:"[Guide] \u767c\u4f48 npm \u5957\u4ef6 - \u5f9e\u624b\u52d5\u5230\u81ea\u52d5\uff080\uff09\uff1a\u5c08\u6848\u8207\u5957\u4ef6\u5efa\u7f6e\u7bc7"})}),"\n"]})]})}function h(e={}){const{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},28453:(e,n,s)=>{s.d(n,{R:()=>c,x:()=>t});var l=s(96540);const i={},r=l.createContext(i);function c(e){const n=l.useContext(r);return l.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function t(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:c(e.components),l.createElement(r.Provider,{value:n},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.