A Nuxt 3 starter boilerplate with a lot of useful features.
- This project using
npmas package manager - Clone this project to your computer
git clone https://github.com/yuzumi/nuxt3-boilerplate - Install dependencies
npm install - Run
npm run devto start development server and openhttp://localhost:3000in your browser
Make sure to install the dependencies:
npm installEnable devtools:
npm run devtools:enableDisable devtools:
npm run devtools:disableManually check types:
npm run typecheckFind ESLint errors:
npm run lintFind ESLint errors and try to fix them:
npm run lint:fixStart the development server on http://localhost:3000
npm run devBuild the application for production:
npm run buildLocally preview production build:
npm run previewCheck out the deployment documentation for more information.
Create and start the development container:
make dev-upStop and remove the development container:
make dev-downCreate and start the production container:
make prod-upStop and remove the production container:
make prod-down-
srcdirectory - ESLint
- Strict type-checking
- Husky & Lint-staged
- i18n
- VueUse
- Pinia
- Nuxt DevTools
- Vitest
- Layouts
- Error page
- 404 page
- Global types
- Composables
-
Set
srcDiroption innuxt.configfile.// nuxt.config.ts export default defineNuxtConfig({ srcDir: 'src/', });
-
Install needed devDependencies
npm i -D eslint eslint-plugin-vue
npm i -D typescript @typescript-eslint/eslint-plugin @typescript-eslint/parser @nuxtjs/eslint-config-typescript
-
Generate config file
npx eslint --init > How would you like to use ESLint? To check syntax and find problems > What type of modules does your project use? JavaScript modules (import/export) > Which framework does your project use? Vue.js > Does your project use TypeScript? Yes > Where does your code run? Node > What format do you want your config file to be in? JavaScript > Would you like to install them now? No
// .eslintrc.cjs module.exports = { "env": { "es2021": true, "node": true }, "extends": [ "eslint:recommended", "plugin:vue/essential", "plugin:@typescript-eslint/recommended", "@nuxtjs/eslint-config-typescript" // Add here ], "parserOptions": { "ecmaVersion": 13, "parser": "@typescript-eslint/parser", "sourceType": "module" }, "plugins": [ "vue", "@typescript-eslint" ], "rules": { } };
-
Add task scripts
"scripts": { "lint": "eslint --ext .ts,.js,.vue .", "lint:fix": "eslint --fix --ext .ts,.js,.vue ." },
-
Update your VS Code settings to look like this:
{ "eslint.format.enable": true, "editor.codeActionsOnSave": { "source.fixAll.eslint": true } }
-
Install needed devDependencies
npm i -D vue-tsc typescript @types/node
-
Enable the
typescript.typeCheckoption in yournuxt.configfile.export default defineNuxtConfig({ typescript: { strict: true, typeCheck: true, }, });
-
Optionally add task script to manually check your types with
nuxi.{ "scripts": { "typecheck": "npx nuxi typecheck", }, }
-
Install Husky
npx husky-init && npm install -
Install Lint-staged
npm install --save-dev lint-staged
-
Inside
.husky/pre-commitreplacenpm testwithnpx lint-staged.#!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" npx lint-staged
-
In the root directory of your project, create the file
.lintstagedrc.jsonwith the following contents:{ "*.{js,jsx,vue,ts,tsx}": "npm run lint:fix" }
-
Install VueUse
npm i -D @vueuse/nuxt @vueuse/core
-
Add VueUse to
nuxt.configfile// nuxt.config.ts export default defineNuxtConfig({ modules: [ '@vueuse/nuxt', ], })
-
Install Pinia
npm i pinia @pinia/nuxt
-
Add Pinia to
nuxt.configfile// nuxt.config.ts export default defineNuxtConfig({ imports: { // Auto-import pinia stores defined in `~/stores` dirs: ['stores'] }, modules: [ '@pinia/nuxt', ], pinia: { autoImports: [ 'defineStore', 'storeToRefs', ], }, });
-
To enable devtools run:
npm run devtools:enable
-
To disable devtools run:
npm run devtools:disable
-
Install the following dependencies:
npm i -D vitest jsdom @vitejs/plugin-vue
npm i -D @vue/test-utils @nuxt/test-utils
-
Create your Vitest configuration file (vitest.config.js):
// vitest.config.js import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' export default defineConfig({ plugins: [vue()], test: { globals: true, environment: 'jsdom', }, })
-
Add the following script to your project:
{ "scripts": { "test": "vitest" } } -
Create your first test:
// tests/components/HelloWorld.vue import { describe, it, expect } from 'vitest' import { mount } from '@vue/test-utils' import HelloWorld from '../../src/components/HelloWorld.vue'; describe('HelloWorld', () => { it('renders correctly', () => { const wrapper = mount(HelloWorld) expect(wrapper.html()).contain('Hello, world!') }) })
-
At the root of your project create a directory named
typeswith anindex.tsfile. -
Add your global types declaration like in the example below.
// ~/types/index.ts export { }; declare global { interface User { id: string; name: string; email: string; } }
Other templates you may be interested in:
MIT @yuzumi