𝗡𝗼𝗱𝗲.𝗷𝘀 𝟮𝟰 𝗡𝗮𝘁𝗶𝘃𝗲 𝗧𝘆𝗽𝗲𝗦𝗰𝗿𝗶𝗽𝘁
ਬਿਲਡ ਸਟੈਪ (build step) ਲਗਭਗ ਖਤਮ ਹੋ ਗਿਆ ਹੈ।
Node.js 24 ਹੁਣ TypeScript ਨੂੰ natively ਸਪੋਰਟ ਕਰਦਾ ਹੈ। ਤੁਸੀਂ ਬਿਨਾਂ ਕਿਸੇ ਬਿਲਡ ਸਟੈਪ ਦੇ production ਵਿੱਚ .ts ਫਾਈਲਾਂ ਚਲਾ ਸਕਦੇ ਹੋ। ਇਹ ਤੁਹਾਡੇ ਕੋਡ ਅਤੇ ਇਸਦੇ execution ਦੇ ਵਿਚਕਾਰਲੇ ਰੁਕਾਵਟਾਂ ਨੂੰ ਖਤਮ ਕਰਦਾ ਹੈ।
ਇਹ ਕਿਵੇਂ ਕੰਮ ਕਰਦਾ ਹੈ: Runtime ਤੁਹਾਡੇ TypeScript syntax ਨੂੰ parse ਕਰਦਾ ਹੈ। ਇਹ load time 'ਤੇ type annotations ਨੂੰ ਹਟਾ ਦਿੰਦਾ ਹੈ। ਫਿਰ ਇਹ ਨਤੀਜੇ ਵਜੋਂ ਨਿਕਲਣ ਵਾਲੇ JavaScript ਨੂੰ execute ਕਰਦਾ ਹੈ।
ਇਸ ਬਦਲਾਅ ਬਾਰੇ ਮੁੱਖ ਤੱਥ:
- ਇਹ type checking ਨਹੀਂ ਕਰਦਾ।
- ਇਹ .d.ts ਫਾਈਲਾਂ ਨਹੀਂ ਬਣਾਉਂਦਾ।
- ਇਹ TypeScript ਨੂੰ annotated JavaScript ਵਜੋਂ ਮੰਨਦਾ ਹੈ।
- Runtime execution ਤੋਂ ਪਹਿਲਾਂ annotations ਨੂੰ ਰੱਦ ਕਰ ਦਿੰਦਾ ਹੈ।
ਇਹ ਤੁਹਾਡੇ deployment ਨੂੰ ਸਰਲ ਬਣਾਉਂਦਾ ਹੈ। ਤੁਹਾਨੂੰ ਹੁਣ deployment ਲਈ tsc output directories ਜਾਂ ਗੁੰਝਲਦਾਰ source map configurations ਨੂੰ ਮੈਨੇਜ ਕਰਨ ਦੀ ਲੋੜ ਨਹੀਂ ਹੈ। ਤੁਹਾਡਾ source code ਹੀ ਤੁਹਾਡਾ ਇੱਕਮਾਤਰ ਸੱਚ (single source of truth) ਬਣ ਜਾਂਦਾ ਹੈ।
ਇਹਨਾਂ ਸੀਮਾਵਾਂ (limitations) ਦਾ ਧਿਆਨ ਰੱਖੋ:
- Runtime 'ਤੇ ਕੋਈ type checking ਨਹੀਂ। ਗਲਤੀਆਂ ਫੜਨ ਲਈ ਤੁਹਾਨੂੰ ਅਜੇ ਵੀ ਆਪਣੇ CI pipeline ਵਿੱਚ
tsc --noEmitਚਲਾਉਣ ਦੀ ਲੋੜ ਹੈ। - tsconfig.json path mappings ਲਈ ਕੋਈ ਸਪੋਰਟ ਨਹੀਂ।
- decorators ਜਾਂ custom transformers ਲਈ ਕੋਈ ਸਪੋਰਟ ਨਹੀਂ।
- Type stripping ਕਾਰਨ cold starts ਦੌਰਾਨ ਥੋੜ੍ਹਾ ਪ੍ਰਦਰਸ਼ਨ (performance) ਦਾ ਨੁਕਸਾਨ ਹੋ ਸਕਦਾ ਹੈ।
ਜੇਕਰ ਤੁਸੀਂ @/utils ਵਰਗੇ path aliases ਦੀ ਵਰਤੋਂ ਕਰਦੇ ਹੋ, ਤਾਂ ਤੁਹਾਨੂੰ ਅਜੇ ਵੀ ਇੱਕ bundler ਜਾਂ esbuild ਦੀ ਲੋੜ ਹੋਵੇਗੀ।
ਇਸਦੀ ਵਰਤੋਂ ਕਿਵੇਂ ਕਰੀਏ:
ਤੁਸੀਂ ਆਪਣੇ server ਨੂੰ ਸਿੱਧਾ Node ਨਾਲ ਚਲਾ ਸਕਦੇ ਹੋ:
node src/server.ts
ਬਿਹਤਰ debugging ਲਈ, source maps flag ਦੀ ਵਰਤੋਂ ਕਰੋ:
node --enable-source-maps src/server.ts
ਇਹ ਸਰਲ dependency graphs ਵਾਲੇ microservices ਲਈ ਇੱਕ ਵਧੀਆ ਚੋਣ ਹੈ। ਤੁਹਾਨੂੰ deployment ਵਿੱਚ ਤੇਜ਼ੀ ਮਿਲੇਗੀ। ਹਾਲਾਂਕਿ, ਜੇਕਰ ਤੁਹਾਨੂੰ ਭਾਰੀ optimization ਜਾਂ minification ਦੀ ਲੋੜ ਹੈ, ਤਾਂ ਰਵਾਇਤੀ build pipeline ਦੀ ਹੀ ਵਰਤੋਂ ਕਰੋ।
ਮਕਸਦ ਸੰਦ (tool) ਨੂੰ ਤੁਹਾਡੀਆਂ ਖਾਸ ਲੋੜਾਂ ਦੇ ਅਨੁਕੂਲ ਬਣਾਉਣਾ ਹੈ।