How to add Vuepress on a Nuxt project in a proper way? - vue.js

I have my Nuxt app and I'm trying to add Vuepress on it.
I did yarn add vuepress#next -D then created the docs folder and a readme.md file in there.
The problem: The project only shows the sidebar and navbar if the .vuepress folder is outside of the docs folder; If it's inside, it won't work - Not respecting the config.js rules.
Also, it's recognising the readme.md from the Nuxt app (outside from docs folder too), not the one inside docs folder.
Can anyone help me with that?
Another question, if this above works, Am I be able to access through localhost:3000/docs instead of localhost:3000 for the Nuxt project and localhost:8080 for the docs?
That's my current folder structure (no sidebar showing - not respecting the config.js inside the .vuepress folder):
docs
|__.vuepress
| |__config.js
|
|__guides
The config.js file:
module.exports = {
title: 'Documentation',
description: 'Documentation',
themeConfig: {
sidebar: 'auto',
nav: [{
text: 'Home',
link: '/'
},
{
text: 'Guides A',
link: '/guides/apis/'
},
{
text: 'item with subitems',
items: [{
text: 'Subitem 01',
link: '/'
},
{
text: 'SubItem 02',
link: '/'
}
]
},
{
text: 'External',
link: 'https://google.com'
},
]
}
}
Vuepress version 1.0.2
Thanks.

Why you need to use both of these? If you using Nuxt you don't actually need VuePress. Check the official VuePress documentation.
Nuxt
Nuxt is capable of doing what VuePress does, but it is designed for building applications. VuePress is focused on content-centric static sites and provides features tailored for technical documentation out of the box.

Related

Vuepress - Components customized

I'm new in Vuepress. I want to make a blog with a Vuepress-theme is available from github:
https://github.com/vuepress/vuepress-theme-blog
The official documentation shows how to change some things, for example the header, footer... as a colours, links... here more info:
https://vuepress-theme-blog.ulivz.com/config/#nav
To custom the allow parameters is from the file config.js with from module.exports object:
module.exports = {
themeConfig: {
nav: [
{
text: 'Blog',
link: '/',
},
{
text: 'Tags',
link: '/tag/',
},
]
},
}
But I would like to change the full navbar component. For this only I have found the way inside:
/node_modules/#vuepress-themeblog/components/Header.vue
At summary I want to know the best way to create new components. Maybe it's the better option change directly inside the components folder of the theme or is there any way?
I'm very confused in the documentation only shows a little changes.
Please Could you give me some advice?
Thanks!
You shouldn't edit the code inside the node_modules dir, as it is third-party code managed by the package manager.
You can solve your problem by creating your own theme using the vuepress-themeblog as a starting point.
The steps to write custom themes are described in the documentation. Copy the content of the vuepress-theme-blog repository into your theme folder and start working on your custom components.

Vue PWA plugin adjusting iconPaths and manifest destination

I have attached 2 screenshots, one of my vue.config.js and another of a section of the unminified output my build is producing.
Whats happening is this: I want to change the icon paths and the path to the manifest. For whatever reason the official way of changing this is not working. Right now they are blank spaces, however it was not working when it was anything else either ( just tried with 'foo/bar' as the path as I was typing this to triple check ).
I am confused because I seem to be doing everything exactly as I should according to the official docs. Is there anything another set of eyes can spot that I am missing?
Greetings Erik White
At some point I had the same difficulty and solved it as follows:
Copy the images into the "public" folder
example:
We add the folder "favicon" to "public", "favicon" contains 5 images
[project]/public/favicon/favicon-32x32.png
[project]/public/favicon/favicon-16x16.png
[project]/public/favicon/apple-touch-icon-152x152.png
[project]/public/favicon/safari-pinned-tab.svg
[project]/public/favicon/msapplication-icon-144x144.png
To add images in your html: modify the "vue.config.js" and add.
// Inside vue.config.js
module.exports = {
  // ... other vue-cli plugin options ...
  pwa: {
  // ...
    iconPaths: {
      favicon32: 'favicon/favicon-32x32.png',
      favicon16: 'favicon/favicon-16x16.png',
      appleTouchIcon: 'favicon/apple-touch-icon-152x152.png',
      maskIcon: 'favicon/safari-pinned-tab.svg',
      msTileImage: 'favicon/msapplication-icon-144x144.png'
    }
  // ...
  }
}
To change the path and name of "manifest.json" modify the "vue.config.js" and add:
// Inside vue.config.js
module.exports = {
  // ... other vue-cli plugin options ...
  pwa: {
  // ...
    manifestPath: 'my_new_manifest.json',
  // ...
  }
}
To change the properties of the "manifest.json", (name, images, color, etc) modify the "vue.config.js" and add:
// Inside vue.config.js
module.exports = {
// ... other vue-cli plugin options ...
pwa: {
// ...
manifestOptions: {
name: 'etc ..',
short_name: 'etc ..',
theme_color: '# f44647',
background_color: '# f44647',
start_url: 'index.html',
display: 'standalone',
orientation: 'portrait',
icons: [
{
src: './favicon/favicon-32x32.png',
sizes: '32x32',
type: 'image/png'
},
{
src: './favicon/favicon-16x16.png',
sizes: '16x16',
type: 'image/png'
},
{
src: './favicon/apple-touch-icon-152x152.png',
sizes: '152x152',
type: 'image/png'
},
{
src: './favicon/safari-pinned-tab.svg',
sizes: '942x942',
type: 'image/svg+xml'
},
{
src: './favicon/msapplication-icon-144x144.png',
sizes: '144x144',
type: 'image/png'
},
]
},
// ...
}
}
NOTE
chucks is not a supported parameter.
excludeChucks is not a supported parameter.
If you need to test a service worker locally, build the application and run a simple HTTP-server from your build directory. It's recommended to use a browser incognito window to avoid complications with your browser cache.
Remember to see the VUE documentation, it is very detailed, I leave you a link below #vue/cli-plugin-pwa
Nevermind, solved by updating my dependencies.
guessing this was fixed in a patch i didnt catch

Link to main Vue site from Vuepress

I have a vuepress site which lives in my current vuejs app at /docs.
I am building the site into the main /dist folder and deploying them together.
When I am adding a link to the navbar in the .vuepress/config.js file the base is always appended or if adding the full URL it creates an external link.
module.exports = {
base: "/docs/",
dest: "dist/docs",
themeConfig: {
nav: [
{ text: 'Home', link: 'https://myapp.com/'},
{ text: 'Guide', link: '/guide/'}
],
}
}
I can change the way external links are handled, but this is site wide and I do not want this to apply to all links.
In short:
{ text: 'Home', link: '/'} // this is directing to /docs due to base
I would like, for this to direct to myapp.com

Nuxt Sites not getting crawled

I have made a website using NUXT that needs SEO
When I use www.xml-sitemaps.com website to see if it can find all my pages, it only finds the home page, and none of the other routes. When I try other NUXT demo websites it finds them all.
My robots.txt file looks like:
User-agent: *
Disallow: /profile/
Sitemap: https://www.example.com/sitemap.xml
I am using #nuxtjs/sitemap to generate the sitemap.xml that ends up looking something like this:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url> <loc>https://www.example.com/about</loc> </url>
<url> <loc>https://www.example.com/</loc> </url>
</urlset>
And if this helps, my nuxt.config.js looks like:
module.exports = {
/*
** Headers of the page
*/
head: {
title: 'Title',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: 'Title' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
]
},
mode: 'spa',
loading: { color: '#3B8070' },
build: {
/*
** Run ESLint on save
*/
extend (config, { isDev, isClient }) {
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
}
}
},
css: [
'~/assets/main.css'
],
modules: [
'#nuxtjs/pwa',
[
'#nuxtjs/sitemap', {
generate: true,
hostname: 'https://www.example.com',
exclude: [
'/profile'
]
}
]
],
plugins: [
'~/plugins/uikit.js',
'~/plugins/fireauth.js'
],
manifest: {
name: 'Title',
lang: 'en'
},
router: {
middleware: 'router-auth'
},
vendor: [
'firebase',
'uikit'
]
}
I'm the creator of the nuxt sitemap module.
Your sitemap-module configuration is set in the wrong section.
Please, update your nuxt.config.js:
modules: ['#nuxtjs/pwa', '#nuxtjs/sitemap'],
sitemap: {
generate: true,
hostname: 'https://www.example.com',
exclude: [
'/profile'
]
},
plugins: [
Then run npm run generate.
Finally check your generated sitemap.xml in the \dist\ folder.
(If you have an other issue or question, you may open an issue on github project: https://github.com/nuxt-community/sitemap-module/issues)
It's important to understand what's going on with different Nuxt.js modes. Read the explanation about server side rendering in the Nuxt.js Guide, where they explain the difference between the three modes the framework can be configured to work in:
Universal (with server side rendering, so that when any page is rendered, that page will be served with all HTML rendered (SEO and crawler friendly mode)
SPA (Single Page Application) which will serve up the HTML skeleton together with css and javascript bundles, which will only be unbundled to create the initial DOM in the browser. Cool for intranet apps, bad for SEO.
Static generation of all pages (pre-rendering) so that the site can be served up in any shared hosting as simple HTML.
Once the concepts are clear, you can try changing the "mode" property in your Nuxt.js configuration file from "SPA" to "Universal", together with the other suggestion regarding xml sitemap configuration in the same nuxt.config.js file.
Additionally, you can try out and learn about different configurations by either using:
The Nuxt.js starter template discussed in the Installation Guide.
Something like Create Nuxt App that, once installed via npm install -g create-nuxt-app allows you to see how many different configurations are automatically set up for you.
Since you are in SPA mode you will not get much success with SEO, if you can run in universal mode then you will see full benefit of nuxt/vue.
See this website I did with Nuxt in universal mode.

Using Durandal dojoConfig and ESRI Maps

I'm trying to get ESRI maps working with Durandal and came across this link in the Durandal docs DurandalEsri
This seems to work but now Durandal is having problems finding some of my .js files. If I leave the following dojoConfig out my scripts are found but then the maps won't work.
`var dojoConfig = {
baseUrl: './',
async: true,
tlmSiblingOfDojo: true,
parseOnLoad: false,
aliases: [['text', 'dojo/text']],
packages: [
{ name: 'esri', location: '//serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/esri' },
{ name: 'dojo', location: '//serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/dojo/dojo' },
{ name: 'dojox', location: '//serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/dojo/dojox' },
{ name: 'dijit', location: '//serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/dojo/dijit' },
{ name: 'durandal', location: 'App/durandal' },
{ name: 'views', location: 'App/views' },
{ name: 'viewmodels', location: 'App/viewmodels' },
{ name: 'lib', location: 'App/lib' }
]
};`
My app structure looks like this:
App
durandal
lib
services
viewmodels
views
So in my shell.js file if I try to pass in 'lib/config' I get a 404 because it tried to find the config file at localhost/lib/config.js instead of localhost/dashboard/app/lib/config.js
If I pass 'dashboard/app/lib/config' to shell.js the file will be found, but it doesn't seem like I should have to specify the entire path, since 'durandal/system' and anything else under the 'durandal' folder get found correctly.
Any ideas???
I encountered a similar problem using AMD module loading with Esri. I solved it using a configuration similar to yours but with the following baseurl:
baseUrl: location.pathname.replace(/\/[^/]+$/, '') + '/path/to/app/main'
As described in Jeffrey Grajkowski's answer to my question here: https://stackoverflow.com/a/15390919/1014822
So for my scenario of Durandal + Esri + Dojo, I had to leave out the require.js file that is included with Durandal and use the dojo AMD loader. Unfortunately I have no idea what future problems this might cause.
More info can be found here