feat: emit type="module" on Vite script bundles#17
Merged
Conversation
Vite always outputs ES modules, so production script tags need type="module" or the browser fails to parse the import statements. The attribute was only being added in development; this change applies the same default in production for Vite manifests and adds an opt-in Module property on the script-bundle tag helper (plus matching parameters on IAssetService.GetScriptTagAsync and ITagBuilder.BuildScriptTag) for explicit override in either direction. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17 +/- ##
==========================================
- Coverage 73.40% 73.14% -0.26%
==========================================
Files 12 12
Lines 282 283 +1
Branches 63 63
==========================================
Hits 207 207
- Misses 71 72 +1
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Summary
type="module"or the browser refuses to parse the file's top-levelimportstatements. The attribute was previously only emitted in development; this change applies the same default in production for Vite manifests.Moduleproperty onScriptBundleTagHelper(with matchingbool? moduleparameter onIAssetService.GetScriptTagAsyncandITagBuilder.BuildScriptTag) so the attribute can be forced on or off independent of the manifest type.modulecan be used as a parameter name without VB keyword-collision warnings.Behavior
type="module"<script-bundle name="x" /><script-bundle name="x" module="false" /><script-bundle name="x" /><script-bundle name="x" module="true" />Test plan
dotnet buildclean on net8/net9/net10dotnet test— all 97 tests pass on net8/net9/net10BuildScriptTag_ProductionVite_*test updated to assert the now-correct behaviormodule: true/module: falseoverrides in both dev and prodUncaught SyntaxError: Cannot use import statement outside a moduleno longer occurs after bumping the package reference🤖 Generated with Claude Code