Giter Club home page Giter Club logo

vite-vue2-vuetify-ts-starter's Introduction

Vite + Vue 2 + TypeScript + Vuetify

logo

⚠ Important Notice: Vue 2 will reach End of Life (EOL) on December 31st, 2023. For this reason, we do not recommend using this template for new projects. See Vue 2 LTS, EOL & Extended Support.

Vuetify3 version is here.

This is a starter project that uses Vuetify as the UI framework.

Description

This template is for using Vue2 with TypeScript in Vite. Includes vue-router and Vuex.

In addition, ESLint, Stylelint, and Prettier are also included and are set to be executed automatically at runtime and commit. (Since these settings are set strictly, please relax yourself.)

Also, when the development server is executed, it is checked in real time by vite-plugin-checker.

Vitest is included in the program for testing.

First define VITE_APP_TITLE in your .env file.

Known issue

vue-tsc outputs an error with v-checkbox. (Because of the specification to write v-model and value together)

If you encounter this kind of trouble, set vueTsc: false in vite-plugin-checker in vite.config.ts and remove vue-tsc --noEmit from the build command in package.json.

Composition API

With the standard support for Composition API in vue 2.7, the default format is composition api.

vue-property-decorator has been dropped since 0.9.1. Please install manually if necessary.

Teleport

Vue3 adds a mechanism called Teleport, which allows you to install vue components anywhere. This starter template is for vue2, but you can do the same with @logue/vue2-helpers/vue2-teleport.

Teleport JSON-LD Example

If you want to include JSON-LD, enter as follows.

<template>
  <div class="container">
    ... Some Content
    <teleport to="head">
      <component :is="'script'" type="application/ld+json" v-text="jsonLd" />
    </teleport>
  </div>
</template>

<script>
import { defineComponent, ref } from 'vue';

export default defineComponent({
  setup() {
    const jsonLd = ref(
      JSON.stringfy({
        '@schema': 'https://json.schemastore.org/jsonld.json',
        '@context': 'http://schema.org',
        '@type': 'WebSite',
        name: 'Vite Vue2 Vuetify TypeScript Startar',
        url: 'https://github.com/logue/vite-vue2-vuetify-ts-starter',
        description: 'Vite Vue2 Vuetify TypeScript Demo Page',
      })
    );

    return {
      jsonLd,
    };
  },
});
</script>

JSON-LD is literally a script, so it can't be embedded directly, so it's a roundabout thing like this, but simple things like meta tags are reflected by simply inserting a tag.

⚠ Notice: <component :is="'script'" ... /> becomes <component :as="'script'" ... /> in Vue3.

Vue i18n

If you want to use vue-i18n, please install intlify-unplugin-vue-i18n and call the instance with useI18n().

In addition, the conventional method using $t() written in non composition-api can be used as it is.

Recommended IDE Setup

VSCode + Volar (and disable Vetur).

And use Volar Takeover Mode for better performance.

Commands

It is designed to be close to create-vue commands.

Command Description
dev Start devserver.
clean Clear devserver cache.
type-check Check vue markup.
lint Run ESLint and prettier.
lint:style Run Stylelint.
test Run vitest
test:unit Run Unit test
coverage Output Coverage Report.
build Build for production.
build:analyze Execute Bundle Analyzer
build:clean Clear production build files.
build-only Build for production without checking.
preview Run the program generated by the production build.

⚠ Notice: Be sure to use build-only as the build command for auto-deploying to Github Pages, Vercel, CloudFlare pages, etc. build is for checking whether the build passes locally, and an error occurs because it is executed without Meta.ts being created.

Migrate from VueCli

It also works when migrating from VueCLI.

However, when importing a stylesheet with @import, it cannot be specified from the library directory. Must be specified from ./node_modules/.

Troubleshooting

When adding or deleting files, an error may occur and even if the error is corrected, it may not be reflected in devserver. In that case, stop devserver and delete all the files in the node_modules/.vite directory. You can also run it with the clean command.

Due to yarn issues, it may not work properly if the path contains non-ASCII characters (such as 日本語 or 한국어, 中文 etc.).

From 0.7.4, the default project type is module. If you find a plugin that doesn't work, remove "type": "module" from package.json.

It will not work properly if you are using Node v21.0.0. Please upgrade to 21.1.0 or later.

Checklist

When you use this template, try follow the checklist to update your info properly

  • Change the author name in LICENSE and package.json
  • Change the favicon in public and src/assets
  • Remove the .github folder which contains the funding info
  • Clean up the READMEs and remove routes

See Also

vite-vue2-vuetify-ts-starter's People

Contributors

logue 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

Watchers

 avatar  avatar  avatar

vite-vue2-vuetify-ts-starter's Issues

bug: Cannot view component definition

Hi logue,

I have noticed that a fresh start of the template in vscode doesn't seem to resolve components properly, as seen in the screenshot below, the component is marked red.

Screenshot 2022-05-28 at 7 57 13 PM

I have made a few changes in the code above, by removing the import for component, but the issue persists even when the import is in place. Let me know if you need any additional info.

Best regards,
Ju Ping

TS error when deploying with vercel

So I've been using this template for a simple hobby project that I wanted to deploy with Vercel, but I get this typescript error that I don't get locally when using the build command.



Cloning completed: 704.88ms
--
09:11:01.022 | Looking up build cache...
09:11:01.489 | Build Cache not found
09:11:01.792 | Running "vercel build"
09:11:02.440 | Vercel CLI 28.2.0
09:11:02.740 | Warning: Detected "engines": { "node": ">=16.17.0" } in your `package.json` that will automatically upgrade when a new major Node.js Version is released. Learn More: http://vercel.link/node-version
09:11:02.742 | Running "install" command: `yarn`...
09:11:03.684 | ➤ YN0000: ┌ Resolution step
09:11:03.902 | ➤ YN0002: │ stylelint-config-recommended-scss@npm:7.0.0 [8b30a] doesn't provide postcss (p8f459), requested by postcss-scss
09:11:03.902 | ➤ YN0002: │ vite-vue2-vuetify-ts-starter@workspace:. doesn't provide rollup (p5218d), requested by rollup-plugin-visualizer
09:11:03.903 | ➤ YN0000: │ Some peer dependencies are incorrectly met; run yarn explain peer-requirements <hash> for details, where <hash> is the six-letter p-prefixed code
09:11:03.910 | ➤ YN0000: └ Completed in 0s 225ms
09:11:03.977 | ➤ YN0000: ┌ Fetch step
09:11:55.341 | ➤ YN0013: │ 23 packages were already cached, 676 had to be fetched
09:11:55.345 | ➤ YN0000: └ Completed in 51s 367ms
09:11:55.415 | ➤ YN0000: ┌ Link step
09:12:03.722 | ➤ YN0007: │ vue-demi@npm:0.13.6 [40cc5] must be built because it never has been before or the last one failed
09:12:03.723 | ➤ YN0007: │ esbuild@npm:0.14.49 must be built because it never has been before or the last one failed
09:12:04.028 | ➤ YN0000: └ Completed in 8s 613ms
09:12:04.109 | ➤ YN0000: Done with warnings in 1m 1s
09:12:11.181 | src/components/HelloWorld.vue(136,18): error TS2307: Cannot find module '@/Meta' or its corresponding type declarations.
09:12:11.217 | Error! Command "yarn build" exited with 2

I'm guessing this has to do with the aliases defined in tsconfig.ts but I can't figure out what could be wrong with this.

Using custom icons

Any ideas on how to use custom icons?
The documentation under icons/fonts for Vuetify doesn't seem to work with this example

Vuetify Icons/Fonts Docs

`
import Vue from "vue";
import { UserVuetifyPreset } from "vuetify";
import Vuetify from "vuetify/lib";
import "@mdi/font/css/materialdesignicons.css";
import { VuetifyIcons } from "vuetify/types/services/icons";

Vue.use(Vuetify);

export const options: Partial = {
theme: {
themes: {
light: {
primary: "#0F62FE",
secondary: "#393939",
accent: "#0F62FE",
error: "#DA1E28",
info: "#0443CE",
success: "#198038",
warning: "#F1C21B",
warningOrange: "#FC832C",
},
},
},
icons: {
values: vuetifyToCarbon, // custom icons here
iconfont: "mdi",
},
};

export default new Vuetify(options);
`

Specifically trying to use carbon icons - "@carbon/icons-vue": "^10.40.0"

feature request: module federation

This template worked fine for our corporation for months, a huge thanks from me and the team! However, we have now come to a stage where we need to develop functionalities independently. I have heard and dug into this term "module federation" as a paradigm for frontend micro-service, and I was wondering if there's any possibility that an integration of the "vite-plugin-federation" library into this framework is possible.

TLDR: Any suggestion or possible upgrades in the future such that frontend microservice paradigm is possible?

Best regards,
JU PING

No javascript text is not wrapped in <noscript>

@logue you should consider wrapping the text We're sorry but this site doesn't work properly without JavaScript enabled. Please enable it to continue. in the index.html file in a <noscript></noscript> tag instead of the <div id="app"></div>

feature request: auto infer prop types

Hi logue,

According to this link: kaorun343/vue-property-decorator#303

We can make vue-property-decorator infer prop type from TypeScript types.

Why is this significant:

  1. First, a dry code is a good code, and declaring props like this: @Prop({type: Boolean}) readonly trigger: boolean is not dry.
  2. One can easily forget that explicit prop type declaration is required, leading to unexpected behavior, e.g. a Boolean prop defaults to false but if not explicitly declared, it will result in empty string "" instead of false

Hopefully this gets implemented.

Best regards,
Ju Ping

feature request: Global injection of decorators

Hi logue,

As components grow in quantity, repetitive imports of decorators such as Component and Prop from vue-property-decorator becomes bulky. In this template, auto import of components is achieved by components.d.ts which declares component globally. Is there something similar to this that can be done to remove the imports of decorators as well?

Best regards,
Ju Ping

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.