Giter Club home page Giter Club logo

vite-plugin-virtual-html-template's Introduction

vite-plugin-virtual-html-template

npm version

HTML template for vite app, support flexible virtual URL.

The idea and part of the code for this plugin comes from vite-plugin-html-template.

Motivation

  • Vite need html for entry file, which means we must have
    • projectRoot/index.html for SPA
    • projectRoot/app1.html, projectRoot/app2.html, projectRoot/sub/page/app3.html for MPA
  • Why not we use html template for all entry html
  • Also we should support lodash.template syntax for the html content, like setting <title></title>.

Usage

npm i --save-dev vite-plugin-virtual-html-template
// vite.config.js
import virtualHtmlTemplate from 'vite-plugin-virtual-html-template'

// @see https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    // ...other plugins
    virtualHtmlTemplate(/* options */)
  ]
})

Options

// you can custom template path(default is public/index.html) and page title
{
  // define pages, if SPA uses this plugin, the index page must be set
  pages: {
    index: {
      template: 'public/index.html',
      title: 'Home Page',
      entry: 'src/main.js'
    },
    app: {
      template: 'public/index.html',
      title: 'App Page',
      entry: 'src/app/main.js'
    },
    'sub/other': {
      template: 'public/index.html',
      title: 'Sub Page',
      entry: 'src/sub/other/main.js'
    }
  },
  // expose to template
  data: {
    title: 'Home Page',
  }
}

The key of pages and the URL are associated with the following rules: http://127.0.0.1/${key}.html, where key supports multi-level paths.

After starting the dev server, browse:

The URL structure after the project is constructed is the same as that during development:

vite-plugin-virtual-html-template's People

Contributors

hex-ci avatar

Watchers

 avatar

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.