|
| 1 | +import {defineConfig} from 'vite' |
| 2 | +import VirtualHtml from './src/index.js' |
| 3 | +import Vue from '@vitejs/plugin-vue' |
| 4 | +import Inspect from 'vite-plugin-inspect' |
| 5 | +// @ts-ignore |
| 6 | +import {POS} from './src/index.js'; |
| 7 | + |
| 8 | +export default defineConfig({ |
| 9 | + resolve: { |
| 10 | + alias: { |
| 11 | + 'vue': 'vue/dist/vue.esm-bundler.js' |
| 12 | + } |
| 13 | + }, |
| 14 | + plugins: [ |
| 15 | + Inspect(), |
| 16 | + Vue(), |
| 17 | + VirtualHtml({ |
| 18 | + pages: { |
| 19 | + // demo1 is the html name you access in browser |
| 20 | + demo1: { |
| 21 | + template: '/demo/demo1/demo1.html', |
| 22 | + data: { |
| 23 | + users: ['a','b','c'] |
| 24 | + } |
| 25 | + }, |
| 26 | + 'demo1/index': '/demo/demoIndex1.html', |
| 27 | + 'demo2/': '/demo/demoIndex2.html', |
| 28 | + demo2: '/demo/demo2/demo2.html', |
| 29 | + demo3: { |
| 30 | + template: '/demo/demo3.html' |
| 31 | + }, |
| 32 | + demo4: { |
| 33 | + template: '/demo/template.html', |
| 34 | + data: { |
| 35 | + script: '<script type="module" src="/demo/demo1/demo1.ts"></script>' |
| 36 | + } |
| 37 | + }, |
| 38 | + 'demo1/demo2/demo5': { // multi-level directories, the last (demo5) will be the html name |
| 39 | + template: '/demo/template.html', |
| 40 | + data: { |
| 41 | + script: '<script type="module" src="/demo/demo1/demo1.ts"></script>' |
| 42 | + } |
| 43 | + }, |
| 44 | + demo6: { |
| 45 | + entry: '/demo/demo1/demo1.ts', |
| 46 | + }, |
| 47 | + demo7: { |
| 48 | + entry: '/demo/demo1/demo1.ts', |
| 49 | + title: 'demo7', |
| 50 | + body: '<div id="app"></div>' |
| 51 | + }, |
| 52 | + }, |
| 53 | + data: { |
| 54 | + users: ['a', 'b', 'c'], |
| 55 | + script: '<script type="module" src="/demo/demo1/demo1.ts"></script>' |
| 56 | + }, |
| 57 | + indexPage: 'demo1', |
| 58 | + // global render, from 0.3.0 it (this demo code) will auto configure in plugin, and you MUST install 'ejs' in your project to use it. |
| 59 | + // render(template,data){ |
| 60 | + // return ejs.render(template, data, {delimiter: '%', root: process.cwd()}) |
| 61 | + // }, |
| 62 | + // pages: true, // when pages set to true, plugin will use extraGlobPattern to glob html file |
| 63 | + // extraGlobPattern: [ |
| 64 | + // '**/*.html', |
| 65 | + // '!node_modules/**/*.html', |
| 66 | + // '!.**/*.html', |
| 67 | + // '!dist/**/*.html' |
| 68 | + // ], |
| 69 | + injectCode: { |
| 70 | + 'demo1.html': { |
| 71 | + pos: POS.after, |
| 72 | + find: '<head>', |
| 73 | + replacement: '<script>window.dd = "dd";</script>' |
| 74 | + }, |
| 75 | + '*': { |
| 76 | + pos: POS.after, |
| 77 | + find: '<head>', |
| 78 | + replacement: '<script>window.dd = "bbb";</script>' |
| 79 | + }, |
| 80 | + }, |
| 81 | + // rewrites: [ |
| 82 | + // { |
| 83 | + // from: /.*/g, |
| 84 | + // to: '' |
| 85 | + // } |
| 86 | + // ] |
| 87 | + }), |
| 88 | + ], |
| 89 | + optimizeDeps: { |
| 90 | + force: true |
| 91 | + }, |
| 92 | + // build:{ |
| 93 | + // rolldownOptions:{ |
| 94 | + // input: ['./demo3.html'] |
| 95 | + // } |
| 96 | + // }, |
| 97 | + experimental:{ |
| 98 | + bundledDev: true, |
| 99 | + } |
| 100 | +}) |
0 commit comments