Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/src/htmlPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,9 @@ function createRewire(
baseUrl: string,
proxyUrlKeys: string[],
) {
const regWithBase = path.join(baseUrl, reg)
return {
from: new RegExp(`^/${reg}*`),
from: new RegExp(`^/${reg}*|^${regWithBase}*`),
to({ parsedUrl }: any) {
const pathname: string = parsedUrl.path

Expand Down
2 changes: 2 additions & 0 deletions packages/playground/mpaBase/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NODE_ENV=dev
ENV=env
16 changes: 16 additions & 0 deletions packages/playground/mpaBase/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>test-<%- title %></title>
</head>

<body>
<div id="app"></div>
<div>index app</div>
<div><%- ENV %></div>
<div><%- NODE_ENV %></div>
</body>
</html>
16 changes: 16 additions & 0 deletions packages/playground/mpaBase/other.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><%- title %></title>
</head>

<body>
<div><%- ENV %></div>
<div><%- NODE_ENV %></div>
<div id="app"></div>
<div>other page</div>
</body>
</html>
19 changes: 19 additions & 0 deletions packages/playground/mpaBase/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "playground-map",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build"
},
"dependencies": {
"vite-plugin-html": "workspace:*",
"vue": "^3.2.31",
"vue-router": "^4.0.14"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.2.4",
"@vue/compiler-sfc": "^3.2.31",
"vite": "^2.8.6"
}
}
Binary file added packages/playground/mpaBase/public/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions packages/playground/mpaBase/public/inject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('inject successfully!')
5 changes: 5 additions & 0 deletions packages/playground/mpaBase/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>hello world</div>

<router-view></router-view>
</template>
16 changes: 16 additions & 0 deletions packages/playground/mpaBase/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createApp } from 'vue'
import App from './App.vue'
import { createRouter, createWebHistory } from 'vue-router'
// import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
history: createWebHistory(),
routes: [
{
path: '/test',
component: () => import('./test.vue'),
},
],
})

createApp(App).use(router).mount('#app')
6 changes: 6 additions & 0 deletions packages/playground/mpaBase/src/other-app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<div>
<div>hello world app</div>
<router-view></router-view>
</div>
</template>
15 changes: 15 additions & 0 deletions packages/playground/mpaBase/src/other-main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createApp } from 'vue'
import App from './other-app.vue'
import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
history: createWebHashHistory(),
routes: [
{
path: '/test',
component: () => import('./test.vue'),
},
],
})

createApp(App).use(router).mount('#app')
1 change: 1 addition & 0 deletions packages/playground/mpaBase/src/test.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<template>test</template>
59 changes: 59 additions & 0 deletions packages/playground/mpaBase/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { createHtmlPlugin } from 'vite-plugin-html'

export default defineConfig({
server: {
proxy: {
'/api': 'http://localhost:8080',
},
},
base: '/basetest/',
plugins: [
vue(),
createHtmlPlugin({
minify: true,
pages: [
{
entry: 'src/main.ts',
filename: 'index.html',
template: 'index.html',
injectOptions: {
data: {
title: 'index',
injectScript: `<script src="./inject.js"></script>`,
},
tags: [
{
injectTo: 'body-prepend',
tag: 'div',
attrs: {
id: 'tag1',
},
},
],
},
},
{
entry: 'src/other-main.ts',
filename: 'other.html',
template: 'other.html',
injectOptions: {
data: {
title: 'other page',
},
tags: [
{
injectTo: 'body-prepend',
tag: 'div',
attrs: {
id: 'tag2',
},
},
],
},
},
],
}),
],
})