Git Product home page Git Product logo

nuxt3-eslint-starter's Introduction

Nuxt 3 with Eslint and Tailwindcss

Look at the nuxt 3 documentation to learn more.

Features

Setup

Make sure to install the dependencies:

# yarn
yarn install

# pnpm (Not recommended right now)
# Even with `--shamefully-hoist`, it still not work properly
pnpm install

Development Server

Start the development server on http://localhost:3000

yarn dev

Production

Build the application for production:

yarn build

Locally preview production build:

yarn preview

Checkout the deployment documentation for more information.

Setup Tutorials for other libraries

When you are testing and adding these modules in your project, remember to run yarn dev during your testing process. Some of auto-import feature need to be generated automatically into .nuxt.

Normally, nuxt will generate app.vue to be the entry point of your app. However, if you create pages directory, app.vue will be useless. Therefore, our entry page is pages/index.vue.

Eslint Setup with Typescript

yarn add -D @nuxtjs/eslint-config-typescript eslint

.eslintrc configuration

{
  "extends": ["@nuxtjs/eslint-config-typescript"]
}

Optional: We use eslint to format the code officially. There are some settings that you may want to disable.

  1. On macOS - Code > Preferences > Settings
  2. Search Prettier:Require Config uncheck it in your workspace
{
  "prettier.requireConfig": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  }
}

Recommended extension Tailwind CSS IntelliSense and PostCSS Language Support. You can see the recommended list in extension.json

yarn add -D @nuxtjs/tailwindcss

Optional: Create tailwind.css file in assets/css folder

@tailwind base;
@tailwind components;
@tailwind utilities;

nuxt.config.ts configuration

export default defineNuxtConfig({
  tailwindcss: {
    cssPath: '~/assets/css/tailwind.css',
    configPath: 'tailwind.config',
    // exposeConfig: false,
    // config: {},
    // injectPosition: 0,
    // viewer: true,
  },
  modules: ['@nuxtjs/tailwindcss'],
})

Create tailwind.config.ts and its configuration

import type { Config } from 'tailwindcss'
// import defaultTheme from 'tailwindcss/defaultTheme'

export default <Partial<Config>>{
  theme: {
    extend: {
      colors: {
        primary: '#00FF00',
        // primary: defaultTheme.colors.green
      },
    },
  },
}

Official setting of defaultTheme.colors.green for green is not working

Pinia Setup ๐Ÿ

yarn add @pinia/nuxt

nuxt.config.ts configuration

// nuxt.config.ts
export default defineNuxtConfig({
  // make user stores directory to be able to auto-import without import anything
  imports: {
    dirs: ['stores'],
  },
  modules: [
    [
      '@pinia/nuxt',
      {
        autoImports: ['defineStore', 'acceptHMRUpdate'],
      },
    ],
  ],
})

MSW Setup

Simply follow the instruction and put the starting point into plugins

yarn add -D msw
// msw.client.ts
import { worker } from '@/mocks/browser'

export default defineNuxtPlugin(() => {
  if (process.dev) {
    worker.start({
      onUnhandledRequest: 'bypass',
    })
  }
})

Axios Setup

You have to set interceptors for each purpose of api in apis directory. Then all these file will get imported into plugins/apis.ts.

yarn add -D axios

Use it as a plugin. You can use it like below.

const { $api } = useNuxtApp()
const handleClick = async () => {
  const data = await $api.mountain.getMountains()
}

Device Setup

Previous version is using custom plugin to find out user-agent. However, @nuxtjs/device had already finished the version 3 of the module. Therefore, we use it with pleasure.

yarn add -D @nuxtjs/device
export default defineNuxtConfig({
  modules: ['@nuxtjs/device'],
})

Composable

<script setup>
  const { isMobile } = useDevice()
</script>

Switch a view (Cannot be recognized by ts(2339))

Property '$device' does not exist

It works fine with the function of it.

<div>
  <div v-if="$device.isDesktop">Desktop</div>
  <div v-else>Mobile</div>
</div>

Official example

<script lang="ts" setup>
  const device = useDevice()
</script>

<template>
  <div>
    <div v-if="device.isMobile">Mobile</div>
    <div v-else>Not Mobile</div>
  </div>
</template>

Change a layout dynamically (index.vue)

<script lang="ts" setup>
  const device = useDevice()
  definePageMeta({
    layout: false,
  })
</script>

<template>
  <div>
    <NuxtLayout :name="device.isMobile ? 'mobile':'default'">
      <h1>Home Page</h1>
      The rest of the page
    </NuxtLayout>
  </div>
</template>

VueUse Setup

Its composables are also auto-import to your project โœจโœจโœจ

yarn add -D @vueuse/nuxt @vueuse/core

nuxt.config.ts configuration

export default defineNuxtConfig({
  modules: ['@vueuse/nuxt'],
})

nuxt3-eslint-starter's People

Contributors

keck10361880-pic avatar weicheng2138 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nuxt3-eslint-starter's Issues

Doesn't build on RC8

`
user@MBP-2 nuxt3-eslint-starter % yarn build
yarn run v1.22.19
$ nuxt build
Nuxt CLI v3.0.0-rc.8 13:13:13

ERROR Unexpected token (Note that you need plugins to import files that are not JavaScript)
file: /Users/user/Code/Experiments/nuxt3-eslint-starter/pages/about.vue?vue&type=script&setup=true&lang.ts&macro=true:24:0
22: const counterStore = useCounterStore()
23:
24: return (_ctx: any,_cache: any) => {
^
25: const _component_NuxtLink = _resolveComponent("NuxtLink")!

ERROR Unexpected token (Note that you need plugins to import files that are not JavaScript)

at error (node_modules/vite/node_modules/rollup/dist/es/shared/rollup.js:1858:30)
at Module.error (node_modules/vite/node_modules/rollup/dist/es/shared/rollup.js:12412:16)
at Module.tryParse (node_modules/vite/node_modules/rollup/dist/es/shared/rollup.js:12789:25)
at Module.setSource (node_modules/vite/node_modules/rollup/dist/es/shared/rollup.js:12694:24)
at ModuleLoader.addModuleSource (node_modules/vite/node_modules/rollup/dist/es/shared/rollup.js:22136:20)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
`

Mobile detect from user-agent is outdated.

A page or script is accessing at least one of navigator.userAgent, navigator.appVersion, and navigator.platform. Starting in Chrome 101, the amount of information available in the User Agent string will be reduced.

To fix this issue, replace the usage of navigator.userAgent, navigator.appVersion, and navigator.platform with feature detection, progressive enhancement, or migrate to navigator.userAgentData.

The message recommended you to use navigator.userAgentData as below

uad

However, by the doc they provide, userAgentData is still not yet supported by Firefox and Safari. You have to deal with it.

20220616

Fail to detect ua info by navigator.userAgentData when using ios devices. Those devices will make userAgentData to have wrong and blank data inside...

Component test and E2E test

  • implement vitest. vitest is a testing tool, not for component test.

  • implement E2E test with testcafe

  • vitest works with "@nuxt/test-utils": "^3.0.0-rc.3" to test SSR page.

  • vitest cannot make unit test with @vue/test-utils to mount the component. But require @vitejs/plugin-vue to handle .vue file. Still figuring out...

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.