fix(compiler): preserve bundler directive comments in es5 output#6779
Merged
johnjenkins merged 1 commit intoJul 17, 2026
Merged
Conversation
Terser was stripping the /* @vite-ignore */ and webpack magic comments (webpackInclude, webpackExclude, webpackMode) from the dynamic import() in the lazy loader when transpiling to ES5, because getTerserOptions relied on terser's default comment handling, which only keeps license-style comments. This caused Vite to warn that the dynamic import cannot be analyzed, and webpack to ignore its lazy-loading hints in esm-es5 output. Preserve bundler directive comments through ES5 minification so downstream bundlers can honor them. fixes stenciljs#4122
Contributor
|
hey again @Arul1998 - thanks for looking into this, but ES5 builds are being dropped in the next release of Stencil so this work won't be necessary. |
Contributor
|
Edit ... after looking, I changed my mind as it's such a small change 😅 |
johnjenkins
approved these changes
Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the current behavior?
GitHub Issue Number: #4122
The Stencil runtime's lazy loader (
src/client/client-load-module.ts) annotates its dynamicimport()with bundler directive comments —/* @vite-ignore */,/* webpackInclude: ... */,/* webpackExclude: ... */, and/* webpackMode: "lazy" */— so that downstream bundlers handle the non-statically-analyzable import correctly.With
buildEs5enabled, those comments are lost in thedist/esm-es5output. They survive the TypeScript ES5 transpilation, but are then stripped by terser:getTerserOptionsdoesn't configureformat.comments, so terser's default applies, which only keeps license-style comments (@license,@preserve,/*! ... */).As a result:
The above dynamic import cannot be analyzed by Vite.(this is the warning reported in bug: buildEs5 emits warning with Vite #4122)webpackInclude/webpackExclude/webpackModelazy-loading hints in the es5 output.What is the new behavior?
The ES5 minification options now pass terser a
format.commentspattern that preserves bundler directive comments (@vite-ignoreandwebpack*:magic comments) in addition to terser's default license-comment behavior. The directives now ship in theesm-es5output, Vite no longer warns, and webpack's hints are honored.This is a compiler-only change: it does not add any code to the runtime, and modern (non-es5) output is unaffected. Regular comments are still stripped from es5 output as before.
Documentation
N/A
Does this introduce a breaking change?
Testing
src/compiler/optimize/test/optimize-module.spec.tscovering the ES5 path: bundler directive comments are preserved inside the dynamicimport(), ordinary line/block comments are still removed, and license comments are still preserved.buildEs5enabled against this branch and confirmed the directive comments are present indist/esm-es5. Ran the output through Vite's dev-server transform (vite:import-analysis): the current published output reproduces the exact warning from bug: buildEs5 emits warning with Vite #4122, and the output built with this fix produces no warning.Other information
esm-es5output before this change: