Duplicate decorator helper in each compile Typescript file #1850
Open
Description
- Read the docs.
- Use Vite >=2.0. (1.x is no longer supported)
- If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.
Describe the bug
The following code is embedded in each compiled TypeScript file when decorator is used.
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __decorate = (decorators,target,key,kind)=>{
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
for (var i = decorators.length - 1, decorator; i >= 0; i--)
if (decorator = decorators[i])
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
if (kind && result)
__defProp(target, key, result);
return result;
}
;
While the code above is not going to increase the overall file size, it is good to be able to dedupe such code in a separate bundle and import when needed in each and every compiled TS file that requires it.
Reproduction
- Run
npm init @vitejs/app
and selectlit-element-ts
to scaffold a project - Ensure
vite
is always the latest version - Create a simple
my-app
usinglit-element
and rendermy-app
insidemy-element
- Run
npm run dev
to start the dev server - Access the local dev server and inspect the compiled scripts in the Network tab in Chrome DevTool or equivalent
- The said generated code will be inside each and every compiled TS file
System Info
vite
version: 2.0.0-beta.61- Operating System: Windows 10 x64
- Node version: 15.7.0
- Package manager (npm/yarn/pnpm) and version:
npm@7.4.3
Logs (Optional if provided reproduction)
- Run
vite
orvite build
with the--debug
flag. - Provide the error log here.