@vitejs/plugin-vue will remove the code comment when <script lang="ts">
See original GitHub issueDescribe the bug
my vite plugin:
{
name: 'client-only',
transform(code, id, { ssr } = {}) {
if (ssr) {
// In ssr case, I need to do some transform according to the code comment. eg: //...
return transform(code);
}
},
}
my vite config:
plugins: [
vue(),
clientOnly() // after the vue plugin
]
but I found if the *.vue’ file’s <script> with lang=‘ts’, the comment in code will be remove:
btw, the <script> without lang=‘ts’, will keep the comment
I try to trace the source code
Its like doing something in options.compiler.rewriteDefault
How should I keep the comment? Thanks all
Reproduction
https://stackblitz.com/edit/vitejs-vite-myfppw?file=vite.config.ts&terminal=dev
System Info
System:
OS: macOS 10.15.7
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 636.03 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 16.4.1 - ~/.nvm/versions/node/v16.4.1/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 7.18.1 - ~/.nvm/versions/node/v16.4.1/bin/npm
Browsers:
Chrome: 98.0.4758.102
Safari: 14.0.3
Used Package Manager
yarn
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Code snippet getting auto removed from Additional Comments
Solved: When trying to add a code snippet into the Additional Comments on an Incident, ServiceNow removes it and only displays For example,...
Read more >Does removing comments improve code performance ...
Removing comments will make the Javascript file smaller and easier to download. Other than that, it will not affect noticably performance at all....
Read more >Best practices for writing code comments - Stack Overflow Blog
Rule 1: Comments should not duplicate the code. Rule 2: Good comments do not excuse unclear code. Rule 3: If you can't write...
Read more >Clarifying Code with Javascript Comments | Udacity
This strategy allows you to locate bugs, progressively removing comments until you find the problematic code. Commenting Out Function Calls.
Read more >Putting comments in code: the good, the bad, and the ugly.
Often, a clarification comment is a code smell. It tells you that your code is too complex. You should strive to remove clarification...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Its helpful for me, Thanks, Stared 👍
I don’t think this will be fixed by esbuild soon, and it may as well be intended behaviour for them, as custom comments usually shouldn’t affect the bundling output (except special pure comments etc). So I’ll close this for now.