Skip to content

Commit

Permalink
fix: use lodash.template directly to compile templates
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed May 3, 2024
1 parent 93982b7 commit 5cbffc1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 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 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
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 5cbffc1

Please sign in to comment.