Minimal NuxtJS TypeScript example starter project using Options, Class and Composition APIs (see branches)
see Options API branch.
- generate new npm project from scratch:
mkdir typescript-nuxt-min cd typescript-nuxt-min/ npm init -y
- IMPORTANT: install nux as dependency (not as devDependency!)
npm i -E nuxt
- install
@nuxt/typescript-build
as dev dependency:npm i -ED @nuxt/typescript-build
- add npm-scripts in package.json file:
{ "scripts": { "dev": "nuxt", "build": "nuxt build", "start": "nuxt start", "generate": "nuxt generate" } }
- create tsconfig.json file:
whre
{ "compilerOptions": { "target": "es2018", "module": "esnext", "moduleResolution": "node", "lib": [ "esnext", "esnext.asynciterable", "dom" ], "esModuleInterop": true, "allowJs": true, "sourceMap": true, "strict": true, "noEmit": true, "baseUrl": ".", "paths": { "~/*": [ "./*" ], "@/*": [ "./*" ] }, "types": [ "@nuxt/types" ] } }
@nuxt/types
should not be installed - it's already packages together with@nuxt/typescript-build
. - create nuxt.config.js file:
export default { buildModules: [ '@nuxt/typescript-build', ], }
- create pages/index.vue file:
<template> <div class="app"> <h1>Hello, {{ id }}!</h1> </div> </template> <script lang="ts"> // <--- THIS lang="ts" IS REALLY IMPORTANT! import Vue from 'vue'; export default Vue.extend({ data() { const id: string = 'TypeScript'; return { id, }; } }); </script>
- start development:
npm run dev
- open http://127.0.0.1:3000/
- build and run:
npm run build npx serve dist
- open http://127.0.0.1:5000/
- GitHub Pages deployment located here
see Class API branch.
see Composition API branch.