Skip to content

hantaogo/vite-plugin-vue-insert-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vite-plugin-vue-insert-code

insert template or script to vue sfc.

only for vue3 and vite

install

npm install -D vite-plugin-vue-insert-code

example

// vite.config.ts
export default defineConfig({
  plugins: [
    insertcode({
      // fileRegex: /\.(vue)$/, // skil file when file not match this, default: /\.(vue)$/
      // flag: '<-- insertcode -->', // if flag not empty, skip file when not include this
      // ignoreFlag: '<-- not insertcode -->', // if ignoreFlag not empty, skip file when include this
      rules: [
        {
          // trace every vue sfc file, skip it when this function not return true
          match: path => {
            if (path.includes('Hello World.vue')) {
              return false
            }
            return true
          },
          // add script at top of <script setup>
          addScriptTop: `import Login from './Login.vue'\nimport Loading from ./Loading.vue`,
          // add script at bottom of <script setup>
          addScriptBottom: `showLoading()`,
          // add code at top of <template>
          addTemplateTop: `<Login/>`,
          // add code at bottom of <template>
          addTemplateBottom: `<Loading/>`,
          // show some debug info
          // debug: true,
        }
      ]
    }),
  ],
  // ...
}

About

insert template or script to vue3 sfc.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published