Skip to content

Commit

Permalink
fix(nuxt): use lodash.template directly to compile templates (#1525)
Browse files Browse the repository at this point in the history
* fix: use `lodash.template` directly to compile templates

* chore: add lodash types
  • Loading branch information
danielroe authored Jul 13, 2024
1 parent c20136d commit f62ba9c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"dependencies": {
"@nuxt/kit": "^3.10.3",
"@posva/lru-cache": "^10.0.1",
"lodash-es": "^4.17.21",
"strip-json-comments": "^5.0.1"
},
"peerDependencies": {
Expand All @@ -66,6 +67,7 @@
"@nuxt/module-builder": "^0.8.1",
"@nuxt/schema": "^3.10.3",
"@nuxt/test-utils": "^3.11.0",
"@types/lodash-es": "^4.17.12",
"eslint": "^8.56.0",
"firebase": "^10.8.0",
"firebase-admin": "^12.0.0",
Expand Down
18 changes: 16 additions & 2 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { readFileSync } from 'node:fs'
import { template } from 'lodash-es'
/**
* @module nuxt-vuefire
*/
Expand Down Expand Up @@ -169,7 +171,13 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({

// this adds the VueFire plugin and handle SSR state serialization and hydration
addPluginTemplate({
src: normalize(resolve(templatesDir, 'plugin.ejs')),
getContents({ options }) {
const contents = readFileSync(
normalize(resolve(templatesDir, 'plugin.ejs')),
'utf-8'
)
return template(contents)({ options })
},
filename: 'vuefire-plugin.mjs',
options: {
ssr: nuxt.options.ssr,
Expand Down Expand Up @@ -232,7 +240,13 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
if (options.auth.enabled) {
// hydrates the user if any
addPluginTemplate({
src: normalize(resolve(runtimeDir, 'auth/plugin.client.ejs')),
getContents({ options }) {
const contents = readFileSync(
normalize(resolve(runtimeDir, 'auth/plugin.client.ejs')),
'utf-8'
)
return template(contents)({ options })
},
filename: 'vuefire-auth-plugin.client.mjs',
options: {
...options.auth,
Expand Down
24 changes: 23 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f62ba9c

Please sign in to comment.