Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: works with ssr: false (#149)
Co-authored-by: S茅bastien Chopin <seb@nuxtjs.com>
  • Loading branch information
antfu and Atinux committed Jun 9, 2022
1 parent 26ca7e6 commit 3dde9cb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/module.ts
@@ -1,7 +1,7 @@
import { promises as fsp } from 'fs'
import { join, resolve } from 'pathe'
import template from 'lodash.template'
import { addPlugin, addTemplate, defineNuxtModule, isNuxt2, addComponent, addAutoImport, createResolver } from '@nuxt/kit'
import { addPlugin, addTemplate, defineNuxtModule, addPluginTemplate, isNuxt2, addComponent, addAutoImport, createResolver } from '@nuxt/kit'

import { name, version } from '../package.json'

Expand Down Expand Up @@ -56,9 +56,11 @@ export default defineNuxtModule({

// Nuxt 3 - SSR false
if (!nuxt.options.ssr) {
// @ts-ignore TODO: use nitro plugin
nuxt.hook('nitro:document', (template) => {
template.contents = template.contents.replace('</body>', `</body><script>${options.script}</script>`)
addPluginTemplate({
filename: 'color-mode-script.mjs',
getContents () {
return options.script + '\nexport default () => {}'
}
})
}

Expand Down

0 comments on commit 3dde9cb

Please sign in to comment.