Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate decorator helper in each compile Typescript file #1850

Open
3 tasks done
motss opened this issue Feb 2, 2021 · 4 comments
Open
3 tasks done

Duplicate decorator helper in each compile Typescript file #1850

motss opened this issue Feb 2, 2021 · 4 comments
Labels
bug: upstream Bug in a dependency of Vite enhancement New feature or request

Comments

@motss
Copy link

motss commented Feb 2, 2021

⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.

  • 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

  1. Run npm init @vitejs/app and select lit-element-ts to scaffold a project
  2. Ensure vite is always the latest version
  3. Create a simple my-app using lit-element and render my-app inside my-element
  4. Run npm run dev to start the dev server
  5. Access the local dev server and inspect the compiled scripts in the Network tab in Chrome DevTool or equivalent
  6. 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)

  1. Run vite or vite build with the --debug flag.
  2. Provide the error log here.
@yyx990803 yyx990803 added enhancement New feature or request and removed pending triage labels Feb 2, 2021
@yyx990803
Copy link
Member

This is a limitation because esbuild transpiles TS modules in insolation. I'm not sure if esbuild has an equivalent of TS' importHelpers for this. /cc @evanw

@CarterLi
Copy link

CarterLi commented Feb 4, 2021

You may try vite-plugin-ts, which uses the official TS package to compile .ts(x) files, and support importHelpers, decorator, const enum, emitMetadata, etc.

image

@hjkcai
Copy link

hjkcai commented Mar 21, 2022

Hi! Is there any progress on this issue?

@sapphi-red
Copy link
Member

related: evanw/esbuild#1230

@haoqunjiang haoqunjiang added the bug: upstream Bug in a dependency of Vite label Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: upstream Bug in a dependency of Vite enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants