Giter Club home page Giter Club logo

vite-plugin-vue2-suffix's Introduction

vite-plugin-vue2-suffix

it has been official inclued detail

A plugin solve missing '*.vue' suffix problem transform webpack to vite in vue2


Usage

Install

npm i vite-plugin-vue2-suffix -D

Add it to vite.config.js

// vite.config.js
import { createVuePlugin } from "vite-plugin-vue2";
import VitePluginVue2Suffix from "vite-plugin-vue2-suffix";

export default {
  plugins: [createVuePlugin(), VitePluginVue2Suffix()],
};

That's all.

Situation 1

components using in another components

it will automatically turn this

<template>
  <div class="block">
    <ComponentA msg="this is a A component" />
    <router-view></router-view>
  </div>
</template>

<script>
import ComponentA from "./components/ComponentA";

export default {
  components: {
    ComponentA,
  },
};
</script>

into this

<template>
  <div class="block">
    <ComponentA msg="this is a A component" />
    <router-view></router-view>
  </div>
</template>

<script>
import ComponentA from "./components/ComponentA/index.vue";

/** or if your component is in a outside path  */
// import ComponentA from './components/ComponentA.vue'

export default {
  components: {
    ComponentA,
  },
};
</script>

Situation 2

components using in routes

also, it will turn this:

import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

const routerMap = [
  {
    path: "/news",
    component: () => import("../components/News"),
  },
];

export default new Router({
  scrollBehavior: () => ({
    y: 0,
    x: 0,
  }),
  routes: routerMap,
});

into this below:

import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

const routerMap = [
  {
    path: "/news",
    component: () => import("../components/News.vue"),
    /** or if your component is in a inside path */
    // component: () => import('../components/News/index.vue')
  },
];

export default new Router({
  scrollBehavior: () => ({
    y: 0,
    x: 0,
  }),
  routes: routerMap,
});

License

MIT License © 2021 williamyorkl

vite-plugin-vue2-suffix's People

Contributors

williamyorkl avatar

Stargazers

Curie avatar anchuanyuan avatar  avatar  avatar Yang Guang avatar Souler Ou avatar PENG Rui avatar  avatar Selene avatar

Watchers

 avatar

Forkers

selene-y

vite-plugin-vue2-suffix's Issues

Cannot use import statement outside a module

version is "vite-plugin-vue2-suffix": "^1.0.4",
when i run "npm run vite", i got this:

[0] xxx\node_modules\vite-plugin-vue2-suffix\dist.js:1
[0] import fs from 'fs';
[0] ^^^^^^
[0]
[0] SyntaxError: Cannot use import statement outside a module

my vite.config.js:

import VitePluginVue2Suffix from "vite-plugin-vue2-suffix";
...
    plugins: [
        // 支持vue2
        createVuePlugin({
            jsx: true,
        }),
        VitePluginVue2Suffix(),
        copy(),
    ],

打包问题 与 忽略配置

  1. 打包: 如果作为node_module中包使用, 你可能需要把文件打包成cjm格式.
  2. 希望能自定义忽略规则, 比如匹配某种后缀, 如.js或者其它, 现在我引用的js文件他都当成是vue组件了.

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.