Code Monkey home page Code Monkey logo

lucid-nuxt-2021's Introduction

lucid-nuxt-2021

Prerequisites

First Things First

Build Setup

# use specified node version
$ nvm use

# install dependencies
$ yarn install

# serve with hot reload at localhost:3000
$ yarn dev

# build for production and launch server
$ yarn build
$ yarn start

# generate static project
$ yarn generate

For detailed explanation on how things work, check out Nuxt.js docs.

Scaffolding

Scaffold components and vuex modules:

yarn scaffold

Linting tools

Use with GUI Git Clients (i.e. Sourcetree)

In order to run husky v4+ with Sourcetree one can add a ~/.huskyrc file.

# ~/.huskyrc
# This loads nvm.sh and sets the correct PATH before running hook
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

SASS Architecture

This boilerplate is following the SASS 7-1 pattern.

The architecture consists of:

  • Abstracts: Tools, helpers, functions and mixins
  • Base: Base styles
  • Pages: Specific styles for pages
  • Vendors: External libraries

Note: Not all seven folders of the SASS 7-1 pattern have yet been setup. This is because folders such as /themes are very project specific.

Breakpoints / Media Queries

Add breakpoints to breakpoints.mjs. Breakpoints are available in SASS, Storybook and @nuxt/image.

sass-mq Mixin Usage

@include mq($from: medium) {
  .titanic {
    float: none;
  }
}

VS Code

We recommend to use VS Code. Recommended extensions can be installed (prompt by VS Code) when opening the project for the first time. Project settings ensures that linting with eslint and stylelint works correctly.

Storybook (optional)

Add with @nuxtjs/storybook. Example config in storybookConfig.js.

lucid-nuxt-2021's People

Contributors

dependabot[bot] avatar fabianellenberger avatar jones-s avatar marcoeh avatar sebastianbayer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lucid-nuxt-2021's Issues

Issues with trailing slashes in urls

We should decide whether we want trailing slashes in our urls or not (or add a config option). So we can force trailing slashes or remove them. There should be 301 redirects in place.

Things to consider:

  • When using matomo (or other analytics) there should be only one version of pages. Either with or without trailing slashes. Otherwise both versions appear in the stats.
  • Canonical urls should always point to the correct url version. Adding a debug log that always prints out the canonical link (and rel lang links or other important info likely to cause trouble) would be nice to have.
  • Static hosting platforms (i.e. Netlify) should always redirect to the correct url version. Currently this is a bit tricky with Netlify (see fischer97.ch) but for self-hosted static sites it should be pretty easy to configure apache/nginx.
  • Links within rich text fields from a cms should point to the correct url version.
  • If we use vue-link to render link fields from craft, there is an option to add or remove trailing slashes by using ForNuxtAddSlash or ForNuxtStripSlash respectively.
  • All nuxt-links should point to the correct version
  • There is a trailing slash option for router and sitemap module in nuxt.config.js but apparently it's not considered best practice to force a setting for static sites. We need to check this again.
  • Add one config to rule them all: trailingSlashes: false/true and use it project-wide instead of adding custom configs everywhere this has to be configured.

Naming

frontend-boilerplate and backend-boilerplate repos could be renamed. If we do this, we should also update:

  • all env variables
  • netlify
  • tajo (domain)
  • deploybot

If we keep adding these boilerplates we could switch to some prefixed and versioned versions that also reflect the tech stack, for example:

  • lucid-boilerplate-nuxt-2021
  • lucid-boilerplate-craft-2021

This would allow us to add repos in the future like:

  • lucid-boilerplate-nuxt-ts-2022
  • lucid-boilerplate-craft-2023

nuxt-i18n redirects to browser language in craft preview

Current issue

Craft previews for German pages redirect to English locale if detectBrowserLanguage is enabled. But only for homepages if onlyOnRoot is set. nuxt-i18n config:

detectBrowserLanguage: {
  onlyOnRoot: true,
  useCookie: true,
},

Possible solution if we need browser lang detection

Create a separate deployment to use as a preview target and add some env variable to disable the option. Also it would not be necessary to generate all the pages and the sitemap for this preview-only deployment.

Add preview mode for craft

Links/Inspiration

Issue with i18n and live preview inside iframe

Because of i18n's browser language detection feature the preview for translated pages gets redirected to the default lang. It has something to do with the cookie that's being set. Read more about it in the official docs. I was able to get it working by adding the following settings to nuxt.config.js:

  i18n: {
    detectBrowserLanguage: {
      useCookie: true,
      cookieCrossOrigin: true,
      onlyOnRoot: true,
    },
  },

This kinda works but sometimes the page won't get updated. Data fetching works, but UI does not get updated. So for now I just disabled it like:

  i18n: {
    detectBrowserLanguage: false,
  },

The best solution for this would be to disable the feature entirely for previews, but currently there it seems like there is no way to do this from a plugin for example. Would be nice to just call app.i18n.disableCookies() or something inside of our preview plugin if we detect a preview.

TODO:

  • Currently preview doesn't work (data not being updated and $craftLivePreview not being set) for home pages (de and en)
  • Doesn't work on production env

Configure preview target in Craft

We should aim for a solution that works with the default preview target {url} for sections in Craft.
If we need the language or the site handle for any reason, we can add them like: {url}?language={site.language}&siteHandle={site.handle}.

Check i18n implementation

  • How to handle sites with only one language? Should be as easy as removing the nuxt i18n module.
  • Does it still work with more than two languages? Probably.

Add more helpful error messages when generating a multilang site

https://github.com/wearelucid/zfv-gastro-unibe/blob/main/graphql/scripts/fetchRoutesToBeGenerated.js#L14

This is how things look more or less correct.
In the boilerplate:
we have this:
https://github.com/wearelucid/lucid-nuxt-2021/blob/main/graphql/scripts/fetchRoutesToBeGenerated.js#L14

When generating you get this error:

image

Fetching routes to generate from http://zfv-cms.nitro/api > 17:29:21

ERROR TypeError: Cannot read properties of null (reading 'match') >17:29:22

at _default (graphql/scripts/fetchRoutesToBeGenerated.js:36:11)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async routes (nuxt.config.js:101:25)
at async AsyncCache.load [as _load] (node_modules/@nuxtjs/sitemap/lib/cache.js:18:22)

Instead of wasting 10min of debugging an error message here:
https://github.com/wearelucid/lucid-nuxt-2021/blob/main/graphql/scripts/fetchRoutesToBeGenerated.js#L36

with a hint just like above
"โŒ Couldn't get routes from CMS. Is API_URL defined in .env and your GraphQL endpoint working?"
woudl be awesome.

Preview: Add documentation that preview with Nuxt Live Preview only works when static

Only after yarn generate and yarn start previews start to work locally:
https://nuxtjs.org/docs/features/live-preview/
-> enablePreview should be tested locally with yarn start and not yarn dev

This could maybe be indicated as default text in the preview bar:

Then it can't be missed!

Either this or let the ThePreviewIndicator throw a warning/error, if process.env.NODE_ENV is development.

Add error page (i.e. 404)

Let's add a custom error page.

Things to consider:

  • The link back to the homepage sometimes didn't work in some of our sites. So maybe it's best to render an tag that points to the frontend url. This would ensure that the app get's initialised properly.
  • Components in the default layout (i.e. navigation, footer, etc.) should work correctly. I some of our previous sites these things were broken in the generated version of the app.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.