Skip to content

feat: emit type="module" on Vite script bundles#17

Merged
Baune8D merged 1 commit into
mainfrom
feat/script-bundle-module-type
May 22, 2026
Merged

feat: emit type="module" on Vite script bundles#17
Baune8D merged 1 commit into
mainfrom
feat/script-bundle-module-type

Conversation

@Baune8D

@Baune8D Baune8D commented May 22, 2026

Copy link
Copy Markdown
Owner

Summary

  • Vite always outputs ES modules, so production script tags need type="module" or the browser refuses to parse the file's top-level import statements. The attribute was previously only emitted in development; this change applies the same default in production for Vite manifests.
  • Added an opt-in Module property on ScriptBundleTagHelper (with matching bool? module parameter on IAssetService.GetScriptTagAsync and ITagBuilder.BuildScriptTag) so the attribute can be forced on or off independent of the manifest type.
  • Disabled CA1716 globally so module can be used as a parameter name without VB keyword-collision warnings.

Behavior

Manifest Tag helper Emits type="module"
Vite <script-bundle name="x" /> yes (dev and prod)
Vite <script-bundle name="x" module="false" /> no
Webpack/KeyValue <script-bundle name="x" /> no
Webpack/KeyValue <script-bundle name="x" module="true" /> yes

Test plan

  • dotnet build clean on net8/net9/net10
  • dotnet test — all 97 tests pass on net8/net9/net10
  • Existing BuildScriptTag_ProductionVite_* test updated to assert the now-correct behavior
  • New tests cover module: true/module: false overrides in both dev and prod
  • Verify in a downstream Vite template that the production browser error Uncaught SyntaxError: Cannot use import statement outside a module no longer occurs after bumping the package reference

🤖 Generated with Claude Code

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>
@Baune8D Baune8D merged commit 2e06085 into main May 22, 2026
1 check passed
@codecov

codecov Bot commented May 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.14%. Comparing base (2b09898) to head (a9bc857).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/AspNet.AssetManager/ScriptBundleTagHelper.cs 0.00% 4 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant