-
-
Notifications
You must be signed in to change notification settings - Fork 69
fix(nuxt-module): Fixes nuxt pages #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(nuxt-module): Fixes nuxt pages #211
Conversation
Added consola as part of the `fix(nuxt-module): Fixes nuxt pages` pr.
✅ Deploy Preview for vue-vine ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@angelhdzdev Thanks for making this amazing contribution! I'd like to merge this but I'm also aware that you may have some further changes ... I've noticed that you're willing to add an option |
Thank you a lot for the warm welcome! About hiding the routes behind I realized that because I deleted all Vine pages when Motivation of
|
Thanks for your detailed description. So you mean: in Vine Nuxt module config
Do I misunderstand anything? |
Yes you understood it very well. With the difference that we do not have to exclude the Vine pages behind /vine:excluded path anymore. We can now simply splice the Vine pages from the pages array. Example: vueVineNuxtModule: {
pages: true,
} vueVineNuxtModule: {
pages: false,
} And added a new option that was like the next logical step, for the users who does not wish to see logs: export interface ModuleOptions {
/**
* Enables or disables Vue Vine pages.
*
* If true, pages will be added.
* If false, pages will be removed.
* @default true
*/
pages?: boolean
/**
* Enables or disables Vue Vine logs and warnings.
*
* @default true
*/
logging?: boolean
} And later of course we add pages to the playground and the tests, which I will need help with. Full codeimport type { NuxtPage } from '@nuxt/schema'
import type { PluginOption } from 'vite'
import { defineNuxtModule } from '@nuxt/kit'
import { VineVitePlugin } from 'vue-vine/vite'
import { consola } from 'consola'
// Module options TypeScript interface definition
export interface ModuleOptions {
/**
* Enables or disables Vue Vine pages.
*
* If true, pages will be added.
* If false, pages will be removed.
* @default true
*/
pages?: boolean
/**
* Enables or disables Vue Vine logs and warnings.
*
* @default true
*/
logging?: boolean
}
function addPages(pages: NuxtPage[], logging?: boolean) {
const count = {sfc: 0, vine: 0}
for (const page of pages) {
if (page.file?.endsWith('vine.ts')) {
page.path = page.path.replace('.vine', '')
page.path = page.path === '/index' ? '/' : page.path
count.vine += 1
} else if (page.file?.endsWith('.vue')) {
count.sfc += 1
}
}
logging && consola.info(`[Vue Vine]: Vine pages enabled.`)
if (pages.length) {
logging && consola.success(`[Vue Vine]: Available pages - Vine (${count.vine}) Vue (${count.sfc})`)
} else {
logging && consola.success(`[Vue Vine]: No pages available.`)
}
}
function removePages(pages: NuxtPage[], logging?: boolean) {
const count = {sfc: 0}
for (const page of pages) {
if (page.file?.endsWith('.vine.ts')) {
pages.splice(pages.indexOf(page), 1)
} else if (page.file?.endsWith('.vue')) {
count.sfc += 1
}
}
logging && consola.info(`[Vue Vine]: Vine pages disabled.`)
if (!pages.find(page => page.path === '/')) {
logging && consola.warn('[Vue Vine]: The index.vue page is missing. Please add it or disable Vue pages by setting `pages: false` in nuxt.config.ts.')
}
if (pages.length) {
logging && consola.success(`[Vue Vine]: Available pages - Vue (${count.sfc})`)
} else {
logging && consola.success(`[Vue Vine]: No pages available.`)
}
}
export default defineNuxtModule<ModuleOptions>({
meta: {
name: '@vue-vine/nuxt',
configKey: 'vueVineNuxtModule',
compatibility: {
// Semver version of supported nuxt versions
nuxt: '>=3.0.0',
},
},
// Default configuration options of the Nuxt module
defaults: {
pages: true,
logging: true,
},
setup(_options, _nuxt) {
_nuxt.options.typescript.tsConfig ||= {}
_nuxt.options.typescript.tsConfig.compilerOptions ||= {}
const compilerOptions = _nuxt.options.typescript.tsConfig
.compilerOptions
compilerOptions.types ||= []
compilerOptions.types.push('vue-vine/macros')
_nuxt.hook('vite:extend', async ({ config }) => {
config.plugins = config.plugins || []
config.plugins.unshift(VineVitePlugin() as PluginOption)
})
_nuxt.hook('pages:extend', (pages) => {
if (!_options.pages) {
removePages(pages, _options.logging)
return
}
addPages(pages, _options.logging)
})
},
}) About the
|
@angelhdzdev Great and awesome !!! Those utility functions are so cool ~~ Would you mind open another PR for these new changes? |
consola : ^3.4.0
to show information about Vue Vine & SFC pages added.