Rodney Vg

Rodney Vg

1588610160

Vite & Vue Powered Static Site Generator

VitePress VuePress’ little brother, built on top of vite

npm install -D vitepress
echo '# Hello VitePress' > index.md

# starts dev server
npx vitepress

# build > .vitepress/dist
npx vitepress build

Note this is early WIP! The default theme is non-existent, but the basic workflow is there.

Customization

Configuration can be done via .vitepress/config.js (see src/config.ts)

You can develop your custom theme by adding the following files:

.vitepress/theme/Layout.vue

<template>
  <h1>Custom Layout!</h1>
  <Content/><!-- make sure to include markdown outlet -->
</template>

.vitepress/theme/index.js

import Layout from './Layout.vue'

export default {
  Layout,
  NotFound: () => 'custom 404', // <- this is a Vue 3 functional component
  enhanceApp({ app, router, siteData }) {
    // app is the Vue 3 app instance from createApp()
    // router is VitePress' custom router (see `lib/app/router.js`)
    // siteData is a ref of current site-level metadata.
  }
}

Unlike VuePress, the only file with a fixed location in a theme is index.js - everything else is imported and exported there like in a normal application.

Motivation

I love VuePress, but being built on top of webpack, the time it takes to spin up the dev server for a simple doc site with a few pages is just becoming unbearable. Even HMR updates can take up to seconds to reflect in the browser!

As a reference, the Composition API RFC repo is just two pages, but it takes 4 seconds to spin up the server, and almost 2 seconds for any edit to reflect in the browser.

Fundamentally, this is because VuePress is a webpack app under the hood. Even with just two pages, it’s a full on webpack project (including all the theme source files) being compiled. It gets even worse when the project has many pages - every page must first be fully compiled before the server can even display anything!

Incidentally, vite solves these problems really well: nearly instant server start, on-demand compilation that only compiles the page being served, and lightning fast HMR. Plus, there are a few additional design issues I have noted in VuePress over time, but never had the time to fix due to the amount of refactoring it would require.

Now, with vite and Vue 3, it is time to rethink what a “Vue-powered static site generator” can really be.

Improvements over VuePress

  • Uses Vue 3.

    • Leverages Vue 3’s improved template static analysis to stringify static content as much as possible. Static content is sent as string literals instead of JavaScript render function code - the JS payload is therefore much cheaper to parse, and hydration also becomes faster.

      Note the optimization is applied while still allowing the user to freely mix Vue components inside markdown content - the compiler does the static/dynamic separation for you automatically and you never need to think about it.

  • Uses vite under the hood:

    • Faster dev server start
    • Faster hot updates
    • Faster build (uses Rollup internally)
  • Lighter page weight.

    • Vue 3 tree-shaking + Rollup code splitting
    • Does not ship metadata for every page on every request. This decouples page weight from total number of pages. Only the current page’s metadata is sent. Client side navigation fetches the new page’s component and metadata together.
    • Does not use vue-router because the need of VitePress is very simple and specific - a simple custom router (under 200 LOC) is used instead.
    • (WIP) i18n locale data should also be fetched on demand.

Other Differences

  • More opinionated and less configurable: VitePress aims to scale back the complexity in the current VuePress and restart from its minimalist roots.

  • Future oriented: VitePress only targets browsers that support native ES module imports. It encourages the use of native JavaScript without transpilation, and CSS variables for theming.

Will this become the next VuePress in the future?

Maybe! It’s currently under a different name so that we don’t over commit to the compatibility with the current VuePress ecosystem (mostly themes and plugins). We’ll see how close we can get without compromising the design goals listed above. But the overall idea is that VitePress will have a drastically more minimal theming API (preferring JavaScript APIs instead of file layout conventions) and likely no plugins (all customization is done in themes).

Download Details:

Author: vuejs

GitHub: https://github.com/vuejs/vitepress

#vuejs #javascript #vue-js

What is GEEK

Buddha Community

Vite & Vue Powered Static Site Generator
Luna  Mosciski

Luna Mosciski

1600583123

8 Popular Websites That Use The Vue.JS Framework

In this article, we are going to list out the most popular websites using Vue JS as their frontend framework.

Vue JS is one of those elite progressive JavaScript frameworks that has huge demand in the web development industry. Many popular websites are developed using Vue in their frontend development because of its imperative features.

This framework was created by Evan You and still it is maintained by his private team members. Vue is of course an open-source framework which is based on MVVM concept (Model-view view-Model) and used extensively in building sublime user-interfaces and also considered a prime choice for developing single-page heavy applications.

Released in February 2014, Vue JS has gained 64,828 stars on Github, making it very popular in recent times.

Evan used Angular JS on many operations while working for Google and integrated many features in Vue to cover the flaws of Angular.

“I figured, what if I could just extract the part that I really liked about Angular and build something really lightweight." - Evan You

#vuejs #vue #vue-with-laravel #vue-top-story #vue-3 #build-vue-frontend #vue-in-laravel #vue.js

Vincent Lab

Vincent Lab

1605177550

Building a Static Website with Hugo

#hugo #static #site #generator #markup #static site generator

Jammie  Yost

Jammie Yost

1656975600

VitePress: Static Site Generator Powered By Vite and Vue.

VitePress (alpha) 📝💨 


VitePress is VuePress' spiritual successor, built on top of vite.

Currently, it's in the alpha stage. It is already suitable for out-of-the-box documentation use, but the config and theming API may still change between minor releases.

Documentation

To check out docs, visit vitepress.vuejs.org.

Changelog

Detailed changes for each release are documented in the CHANGELOG.

Contribution

Please make sure to read the Contributing Guide before making a pull request.


Author: vuejs
Source Code: https://github.com/vuejs/vitepress
License: MIT license

#vite #vue #typescript 

Kevon  Krajcik

Kevon Krajcik

1656741600

Vite SSG: Static Site Generation for Vue 3 on Vite

Vite SSG

Static-site generation for Vue 3 on Vite.

ℹ️ Vite 2 is supported from v0.2.x, Vite 1's support is discontinued.

Install

This library requires Node.js version >= 14

npm i -D vite-ssg vue-router @vueuse/head

// package.json
{
  "scripts": {
    "dev": "vite",
-   "build": "vite build"
+   "build": "vite-ssg build"
  }
}
// src/main.ts
import { ViteSSG } from 'vite-ssg'
import App from './App.vue'

// `export const createApp` is required instead of the original `createApp(App).mount('#app')`
export const createApp = ViteSSG(
  // the root component
  App,
  // vue-router options
  { routes },
  // function to have custom setups
  ({ app, router, routes, isClient, initialState }) => {
    // install plugins etc.
  },
)

Single Page SSG

To have SSG for the index page only (without vue-router), import from vite-ssg/single-page instead, and you only need to install npm i -D vite-ssg @vueuse/head.

// src/main.ts
import { ViteSSG } from 'vite-ssg/single-page'
import App from './App.vue'

// `export const createApp` is required instead of the original `createApp(App).mount('#app')`
export const createApp = ViteSSG(App)

<ClientOnly/>

Component ClientOnly is registered globally along with the app creation.

<client-only>
  <your-client-side-components />
</client-only>

Document head

From v0.4.0, we ship @vueuse/head to manage the document head out-of-box. You can directly use it in your pages/components, for example:

<template>
  <button @click="count++">Click</button>
</template>

<script setup>
import { useHead } from '@vueuse/head'

useHead({
  title: 'Website Title',
  meta: [
    {
      name: `description`,
      content: `Website description`,
    },
  ],
})
</script>

That's all, no configuration is needed. Vite SSG will handle the server-side rendering and merging automatically.

Refer to @vueuse/head's docs for more usage about useHead.

Critical CSS

Vite SSG has built-in support for generating Critical CSS inlined in the HTML via the critters package. Install it via:

npm i -D critters

Critical CSS generation will be enabled automatically for you.

Initial State

The initial state comprises data that is serialized to your server-side generated HTML that is hydrated in the browser when accessed. This data can be data fetched from a CDN, an API, etc, and is typically needed as soon as the application starts or is accessed for the first time.

The main advantage of setting the application's initial state is that the statically generated pages do not need to fetch the data again as the data is fetched during build time and serialized into the page's HTML.

The initial state is a plain JavaScript object that can be set during SSR, i.e., when statically generating the pages, like this:

// src/main.ts

// ...

export const createApp = ViteSSG(
  App,
  { routes },
  ({ app, router, routes, isClient, initialState }) => {
    // ...

    if (import.meta.env.SSR) {
      // Set initial state during server side
      initialState.data = { cats: 2, dogs: 3 }
    }
    else {
      // Restore or read the initial state on the client side in the browser
      console.log(initialState.data) // => { cats: 2, dogs: 3 }
    }

    // ...
  },
)

Typically, you will use this with an application store, such as Vuex or Pinia. For examples, see below:

When using Pinia

Following [Pinia's guide](https://pinia.esm.dev/ssr), you will to adapt your `main.{ts,js}` file to look like this:

// main.ts
import { ViteSSG } from 'vite-ssg'
import { createPinia } from 'pinia'
import routes from 'virtual:generated-pages'
// use any store you configured that you need data from on start-up
import { useRootStore } from './store/root'
import App from './App.vue'

export const createApp = ViteSSG(
  App,
  { routes },
  ({ app, router, initialState }) => {
    const pinia = createPinia()
    app.use(pinia)

    if (import.meta.env.SSR)
      initialState.pinia = pinia.state.value
    else
      pinia.state.value = initialState.pinia || {}

    router.beforeEach((to, from, next) => {
      const store = useRootStore(pinia)
      if (!store.ready)
        // perform the (user-implemented) store action to fill the store's state
        store.initialize()
      next()
    })
  },
)

 

When using Vuex

 

// main.ts
import { ViteSSG } from 'vite-ssg'
import routes from 'virtual:generated-pages'
import { createStore } from 'vuex'
import App from './App.vue'

// Normally, you should definitely put this in a separate file
// in order to be able to use it everywhere
const store = createStore({
  // ...
})

export const createApp = ViteSSG(
  App,
  { routes },
  ({ app, router, initialState }) => {
    app.use(store)

    if (import.meta.env.SSR)
      initialState.store = store.state
    else
      store.replaceState(initialState.store)

    router.beforeEach((to, from, next) => {
      // perform the (user-implemented) store action to fill the store's state
      if (!store.getters.ready)
        store.dispatch('initialize')

      next()
    })
  },
)

 

For the example of how to use a store with an initial state in a single page app, see the single page example.

State Serialization

Per default, the state is deserialized and serialized by using JSON.stringify and JSON.parse. If this approach works for you, you should definitely stick to it as it yields far better performance.

You may use the option transformState in the ViteSSGClientOptions as displayed below. A valid approach besides JSON.stringify and JSON.parse is @nuxt/devalue (which is used by Nuxt.js):

import devalue from '@nuxt/devalue'
import { ViteSSG } from 'vite-ssg'
// ...
import App from './App.vue'

export const createApp = ViteSSG(
  App,
  { routes },
  ({ app, router, initialState }) => {
    // ...
  },
  {
    transformState(state) {
      return import.meta.env.SSR ? devalue(state) : state
    },
  },
)

A minor remark when using @nuxt/devalue: In case, you are getting an error because of a require within the package @nuxt/devalue, you have to add the following piece of config to your Vite config:

// vite.config.ts
// ...

export default defineConfig({
  resolve: {
    alias: {
      '@nuxt/devalue': '@nuxt/devalue/dist/devalue.js',
    },
  },
  // ...
})

Async Components

Some applications may make use of Vue features that cause components to render asynchronously (e.g. suspense). When these features are used in ways that can influence initialState, the onSSRAppRendered may be used in order to ensure that all async operations have finished as part of the initial application render:

const { app, router, initialState, isClient, onSSRAppRendered } = ctx

const pinia = createPinia()
app.use(pinia)

if (isClient) {
  pinia.state.value = (initialState.pinia) || {}
}
else {
  onSSRAppRendered(() => {
    initialState.pinia = pinia.state.value
  })
}

Configuration

You can pass options to Vite SSG in the ssgOptions field of your vite.config.js

// vite.config.js

export default {
  plugins: [],
  ssgOptions: {
    script: 'async',
  },
}

See src/types.ts. for more options available.

Custom Routes to Render

You can use the includedRoutes hook to exclude/include route paths to render, or even provide some complete custom ones.

// vite.config.js

export default {
  plugins: [],
  ssgOptions: {
    includedRoutes(paths, routes) {
      // exclude all the route paths that contains 'foo'
      return paths.filter(i => !i.includes('foo'))
    },
  },
}
// vite.config.js

export default {
  plugins: [],
  ssgOptions: {
    includedRoutes(paths, routes) {
      // use original route records
      return routes.flatMap((route) => {
        return route.name === 'Blog'
          ? myBlogSlugs.map(slug => `/blog/${slug}`)
          : route.path
      })
    },
  },
}

Alternatively, you may export the includedRoutes hook from your server entry file. This will be necessary if fetching your routes requires the use of environment variables managed by Vite.

// main.ts

import { ViteSSG } from 'vite-ssg'
import App from './App.vue'

export const createApp = ViteSSG(
  App,
  { routes },
  ({ app, router, initialState }) => {
    // ...
  },
)
export async function includedRoutes(paths, routes) {
  // Sensitive key is managed by Vite - this would not be available inside
  // vite.config.js as it runs before the environment has been populated.
  const apiClient = new MyApiClient(import.meta.env.MY_API_KEY)

  return Promise.all(
    routes.flatMap(async (route) => {
      return route.name === 'Blog'
        ? (await apiClient.fetchBlogSlugs()).map(slug => `/blog/${slug}`)
        : route.path
    }),
  )
}

Comparsion

Use Vitepress when you want:

  • Zero config, out-of-box
  • Single-purpose documentation site
  • Lightweight (No double payload)

Use Vite SSG when you want

  • More controls on the build process and tooling
  • The flexible plugin systems
  • Multi-purpose application with some SSG to improve SEO and loading speed

Cons:

  • Double payload

Example

See Vitesse

Thanks to the prior work

Contribution

Please refer to https://github.com/antfu/contribute


Author:  antfu
Source Code:  https://github.com/antfu/vite-ssg
License:  MIT license

#vite #vue #typescript #javascript 

Simpliv LLC

Simpliv LLC

1582887678

Training Course on Leverage the Power of Generations | Simpliv

Description
There are now 4 generations in the workplace and our assumptions of the generations is getting in the way of our work. Are you getting along with your team members?

Leverage the Power of Generations aims to generate discussions and open-mindedness that leads to innovative solutions between all age groups. This “generation” course truly applies to every audience and organisation to understand that everyone has something to learn and everyone has something to teach.

Through bite-sized lessons including videos (20 minutes), written material and exercises from your own toolkit, the course focuses on creating common bonds among generations and looking at our differences as assets that can create real change. It is how we choose to work together that determines our success for the future.

Who is the target audience?

Individuals, managers and HR professionals
Basic knowledge
Come with an open mind to learn
What will you learn
To establish that there is conflict among the generations and this is nothing new
Learn that our assumptions about the generations are not always correct
Choose to see our differences among the generations as opportunities not challenges
Learn to be curious, be respectful and find common ground through a common experience
Use tools to guide you to change your perception of the generations
Determine who can help you lead the change process
Understand that everyone has something to learn and something to teach, no matter their generation
Create a dynamic culture of cooperation among the generations

ENROLL

#Leverage The Power Of Generations #Training Course on Leverage the Power of Generations #Leverage the Power of Generations - simpliv #Leverage