Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-virtual-mpa

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-virtual-mpa - npm Package Compare versions

Comparing version 1.6.0 to 1.7.0

14

CHANGELOG.md

@@ -0,12 +1,16 @@

# 1.7.0
- feat: Add preview server's history fallback support. Merged [#26](https://github.com/emosheeep/vite-plugin-virtual-mpa/pull/26)
# 1.6.0
fix: Warnings appear when `build.sourcemap` enabled. Closed [#19](https://github.com/emosheeep/vite-plugin-virtual-mpa/issues/19).
fix: Page doesn't reload when template file change.
feat: Integrate `html-minifier-terser`. Merged [#21](https://github.com/emosheeep/vite-plugin-virtual-mpa/pull/21).
- fix: Warnings appear when `build.sourcemap` enabled. Closed [#19](https://github.com/emosheeep/vite-plugin-virtual-mpa/issues/19).
- fix: Page doesn't reload when template file change.
- feat: Integration of `html-minifier-terser`. Merged [#21](https://github.com/emosheeep/vite-plugin-virtual-mpa/pull/21).
# 1.5.0
feat: Allow vite handling unmatched paths. Closed [#15](https://github.com/emosheeep/vite-plugin-virtual-mpa/issues/15).
- feat: Allow vite handling unmatched paths. Closed [#15](https://github.com/emosheeep/vite-plugin-virtual-mpa/issues/15).
# 1.4.1
fix: Cypress testing process of cross-entry-page jumping hanging, which causing a timeout error. Closed [#12](https://github.com/emosheeep/vite-plugin-virtual-mpa/issues/12).
- fix: Cypress testing process of cross-entry-page jumping hanging, which causing a timeout error. Closed [#12](https://github.com/emosheeep/vite-plugin-virtual-mpa/issues/12).

@@ -13,0 +17,0 @@ # 1.4.0

@@ -22,2 +22,3 @@ "use strict";

rewrites,
previewRewrites,
watchOptions

@@ -52,2 +53,37 @@ } = config;

}
function useHistoryFallbackMiddleware(middlewares, rewrites2 = []) {
middlewares.use(
// @ts-ignore
history({
htmlAcceptHeaders: ["text/html", "application/xhtml+xml"],
rewrites: rewrites2.concat([
{
from: new RegExp(vite.normalizePath(`/${resolvedConfig.base}/(${Object.keys(inputMap).join("|")})`)),
to: (ctx) => {
return vite.normalizePath(`/${resolvedConfig.base}/${inputMap[ctx.match[1]]}`);
}
},
{
/** Vite's default behavior */
from: /.*/,
to: (ctx) => {
const { parsedUrl: { pathname } } = ctx;
return vite.normalizePath((pathname == null ? void 0 : pathname.endsWith(".html")) ? pathname : `${pathname}/index.html`);
}
}
])
})
);
if (verbose) {
middlewares.use((req, res, next) => {
const { url, originalUrl } = req;
if (originalUrl !== url) {
console.log(
`[${pluginName}]: Rewriting ${color.blue(originalUrl)} to ${color.blue(url)}`
);
}
next();
});
}
}
function transform(fileContent, id) {

@@ -157,21 +193,3 @@ const page = virtualPageMap[id];

});
middlewares.use(
// @ts-ignore
history({
htmlAcceptHeaders: ["text/html", "application/xhtml+xml"],
rewrites: (rewrites || []).concat([
{
from: new RegExp(vite.normalizePath(`/${base}/(${Object.keys(inputMap).join("|")})`)),
to: (ctx) => vite.normalizePath(`/${inputMap[ctx.match[1]]}`)
},
{
from: /.*/,
to: (ctx) => {
const { parsedUrl: { pathname } } = ctx;
return vite.normalizePath((pathname == null ? void 0 : pathname.endsWith(".html")) ? pathname : `${pathname}/index.html`);
}
}
])
})
);
useHistoryFallbackMiddleware(middlewares, rewrites);
middlewares.use(async (req, res, next) => {

@@ -183,9 +201,3 @@ const accept = req.headers.accept;

}
const rewritten = url.startsWith(base) ? url : vite.normalizePath(`/${base}/${url}`);
const fileName = rewritten.replace(base, "");
if (verbose && req.originalUrl !== url) {
console.log(
`[${pluginName}]: Rewriting ${color.blue(req.originalUrl)} to ${color.blue(rewritten)}`
);
}
const fileName = url.replace(base, "");
if (!virtualPageMap[fileName]) {

@@ -210,2 +222,5 @@ return next();

});
},
configurePreviewServer(server) {
useHistoryFallbackMiddleware(server.middlewares, previewRewrites);
}

@@ -212,0 +227,0 @@ };

{
"name": "vite-plugin-virtual-mpa",
"version": "1.6.0",
"version": "1.7.0",
"license": "MIT",

@@ -56,7 +56,7 @@ "author": "秦旭洋",

"@types/ejs": "^3.1.1",
"@types/node": "^18.11.18",
"@types/node": "^18.14.0",
"rollup-plugin-node-externals": "^5.1.0",
"typescript": "^4.9.4",
"vite": "^4.0.4",
"vite-plugin-checker": "^0.5.4"
"vite": "^4.1.3",
"vite-plugin-checker": "^0.5.6"
},

@@ -63,0 +63,0 @@ "peerDependencies": {

@@ -24,3 +24,3 @@ # vite-plugin-virtual-mpa ⚡

- 🛠️ Customize the path of generated files, generate multiple files using only one template.
- 🛠️ MPA support & History Fallback API.
- 🛠️ MPA support and History Fallback API for both dev and preview server.

@@ -126,6 +126,11 @@ ## Usage

* Configure your rewrite rules, only proceed html requests.
* further: https://github.com/bripkens/connect-history-api-fallback
* @see https://github.com/bripkens/connect-history-api-fallback
*/
rewrites?: Rewrite[],
/**
* Configure your preview server's rewrite rules.
* @see https://github.com/bripkens/connect-history-api-fallback
*/
previewRewrites?: Rewrite[],
/**
* Sometimes you might want to reload `pages` config or restart ViteDevServer when

@@ -193,3 +198,3 @@ * there are some files added, removed, changed and so on. You can set `watchOptions` to

Click here [codesandbox](https://codesandbox.io/s/vite-plugin-virtual-mpa-0djylc) for a quick preview!
Click here [codesandbox](https://codesandbox.io/p/sandbox/vite-plugin-virtual-mpa-0djylc) for a quick preview!

@@ -249,2 +254,10 @@ ```ts

],
/**
* Configure your preview server's rewrite rules.
* This option is almost the same with `rewrites`.
*/
previewRewrites: [
// If there's no index.html, you need to manually set rules for history fallback like:
{ from: /.*/, to: '/home.html' },
]
}),

@@ -257,3 +270,3 @@ ],

As the examples above says 👆🏻, if you follow the conventions of configurations, this plugin will generate a default rule which looks like:
As the examples above says 👆🏻, if you follow the conventions, this plugin will generate a default rule which will be applied to both dev and preview server, it looks like:

@@ -263,3 +276,3 @@ ```ts

from: new RegExp(normalizePath(`/${base}/(${Object.keys(inputMap).join('|')})`)),
to: ctx => normalizePath(`/${inputMap[ctx.match[1]]}`),
to: ctx => normalizePath(`/${base}/${inputMap[ctx.match[1]]}`),
}

@@ -266,0 +279,0 @@ ```

@@ -24,3 +24,3 @@ # vite-plugin-virtual-mpa ⚡

- 🛠️ 自定义模板HTML文件的输出路径, 使用一份模板生成多份文件
- 🛠️ MPA 多页面应用支持,提供 History Fallback API.
- 🛠️ 支持 MPA 多页面应用,为开发和预览服务器提供 History Fallback 支持.
## 使用方式

@@ -122,7 +122,12 @@

/**
* 配置fallback rewrite rules,只会处理accept=text/html的文件请求
* 详见: https://github.com/bripkens/connect-history-api-fallback
* 为开发服务器配置 fallback rewrite rules,只会处理 accept=text/html 的文件请求。
* @see https://github.com/bripkens/connect-history-api-fallback
*/
rewrites?: Rewrite[],
/**
* 为预览服务器配置重定向规则,配置方式同 rewrites。
* @see https://github.com/bripkens/connect-history-api-fallback
*/
previewRewrites?: Rewrite[],
/**
* 当项目目录下有一些文件触发相应的事件如添加、删除、修改时,你可能想要重新加载 `pages` 配置 或 重启 ViteDevServer。

@@ -186,3 +191,3 @@ * 你可以通过设置 `watchOptions` 来实现这一目的。

点击链接 [codesandbox](https://codesandbox.io/s/vite-plugin-virtual-mpa-0djylc) 快速体验
点击链接 [codesandbox](https://codesandbox.io/p/sandbox/vite-plugin-virtual-mpa-0djylc) 快速体验

@@ -232,5 +237,5 @@ ```ts

/**
* 通过该选项rewrites来配置history fallback rewrite rules
* 通过该选项来配置 history fallback rewrite rules
* 如果你像上面这样配置页面的话,那下面的这份配置将会自动生成。
* 否则你需要自己编写重定向规则,自定义规则将覆盖默认规则。
* 否则你需要自己编写重定向规则。
*/

@@ -243,2 +248,9 @@ rewrites: [

],
/**
* 配置预览服务器的重定向规则,配置方式同 rewrites
*/
previewRewrites: [
// 如果产物目录没有 index.html,你需要手动配置规则,以便服务器能正确找到入口文件。
{ from: /.*/, to: '/home.html' },
]
}),

@@ -251,7 +263,7 @@ ],

正如上面提到的👆🏻,如果你的配置遵循约定,插件将会自动生成一份重定向规则,如下:
正如上面提到的👆🏻,如果你的配置遵循约定,插件将会自动生成一份重定向规则,这份配置会同时应用到开发和预览服务器,如下:
```ts
{
from: new RegExp(normalizePath(`/${base}/(${Object.keys(inputMap).join('|')})`)),
to: ctx => normalizePath(`/${inputMap[ctx.match[1]]}`),
to: ctx => normalizePath(`/${base}/${inputMap[ctx.match[1]]}`),
}

@@ -258,0 +270,0 @@ ```

@@ -74,7 +74,12 @@ import type { FilterPattern, ViteDevServer } from 'vite';

/**
* Configure your rewrite rules, only proceed fallback html requests.
* see: https://github.com/bripkens/connect-history-api-fallback
* Configure your dev server's rewrite rules, only proceed fallback html requests.
* @see https://github.com/bripkens/connect-history-api-fallback
*/
rewrites?: Rewrite[];
/**
* Configure your preview server's rewrite rules.
* @see https://github.com/bripkens/connect-history-api-fallback
*/
previewRewrites?: Rewrite[];
/**
* Sometimes you might want to reload `pages` config or restart ViteDevServer when

@@ -81,0 +86,0 @@ * there are some files added, removed, changed and so on. You can set `watchOptions` to

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc