C

nuxt/4/template-compilation-changes

How to Use
Run this codemod on your codebase using one of the following commands

The easiest way to run this codemod without installing anything globally:

Documentation

This codemod removes lodash/template and related template utilities from Nuxt in favor of a more flexible and secure getContents() function for code generation in v3.

What Changed

Previously, Nuxt used lodash/template to compile templates located on the file system using the .ejs file format/syntax. Additionally, Nuxt provided some template utilities (serialize, importName, importSources) for code generation within these templates. These utilities are now being removed.

Reasons for Change

In Nuxt v3, we moved to a 'virtual' syntax with a getContents() function, which is much more flexible and performant. Additionally, lodash/template has had multiple security issues. Although these issues do not apply to Nuxt projects since it is used at build-time and by trusted code, they still appear in security audits. Moreover, lodash is a hefty dependency and is unused by most projects.

Before

js

After

js

This change applies to all templates using .ejs file format/syntax.

Ready to contribute?

Build your own codemod and share it with the community.