forked from Janlaywss/micro-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3859e59
commit 9035858
Showing
16 changed files
with
142 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,87 @@ | ||
deploy | ||
|
||
## 前言 | ||
我们强烈建议你保持开发环境和线上环境路径(*即webpack的publicPath*)的一致性,以避免在部署后出现问题,无论是基座应用还是子应用。 | ||
|
||
比如一个应用,在部署时作为文件夹 `my-app` 放入服务器根目录,那么配置如下: | ||
<!-- tabs:start --> | ||
#### ** webpack ** | ||
|
||
```js | ||
// webpack.config.js | ||
module.exports = { | ||
output: { | ||
path: 'my-app', | ||
publicPath: process.env.NODE_ENV === 'production' ? '/my-app/' : '', // bad ❌ | ||
publicPath: '/my-app/', // good 👍 | ||
} | ||
} | ||
``` | ||
|
||
#### ** vue-cli ** | ||
```js | ||
// vue.config.js | ||
module.exports = { | ||
outputDir: 'my-app', | ||
publicPath: process.env.NODE_ENV === 'production' ? '/my-app/' : '', // bad ❌ | ||
publicPath: '/my-app/', // good 👍 | ||
} | ||
``` | ||
<!-- tabs:end --> | ||
|
||
## 开始 | ||
正常来说只要开发环境和线上环境资源路径一致,并在部署后设置好nginx的跨域支持,就不会出现问题,在开发环境能够正常运行的项目,部署到服务器也一定可以正常运行。 | ||
|
||
但在实际开发中经常会出现地址404、资源丢失等问题,这通常是因为服务器配置错误或者micro-app元素url属性地址错误导致。 | ||
|
||
我们以[micro-app-demo](https://github.com/micro-zoe/micro-app-demo)为例介绍部署相关内容,以供大家参考,因为`micro-app-demo`覆盖了history路由、hash路由、ssr、根路径、二级路径等大部分场景,是一个典型的案例。 | ||
|
||
**仓库代码的目录结构:** | ||
``` | ||
. | ||
├── child_apps | ||
│ ├── angular11 // 子应用 angular11 (history路由) | ||
│ ├── nextjs11 // 子应用 nextjs11 (history路由) | ||
│ ├── nuxtjs2 // 子应用 nuxtjs2 (history路由) | ||
│ ├── react16 // 子应用 react16 (history路由) | ||
│ ├── react17 // 子应用 react17 (hash路由) | ||
│ ├── sidebar // 子应用 sidebar,公共侧边栏 | ||
│ ├── vite-vue3 // 子应用 vite (hash路由) | ||
│ ├── vue2 // 子应用 vue2 (history路由) | ||
│ └── vue3 // 子应用 vue3 (history路由) | ||
├── main_apps | ||
│ ├── angular11 // 主应用 angular11 (history路由) | ||
│ ├── nextjs11 // 主应用 nextjs11 (history路由) | ||
│ ├── nuxtjs2 // 主应用 nuxtjs2 (history路由) | ||
│ ├── react16 // 主应用 react16 (history路由) | ||
│ ├── react17 // 主应用 react17 (history路由) | ||
│ ├── vite-vue3 // 主应用 vite (history路由) | ||
│ ├── vue2 // 主应用 vue2 (history路由) | ||
│ └── vue3 // 主应用 vue3 (history路由) | ||
├── package.json | ||
└── yarn.lock | ||
``` | ||
|
||
**部署到服务器的目录结构:** | ||
|
||
``` | ||
root(服务器根目录) | ||
├── child | ||
│ ├── angular11 // 子应用 angular11 | ||
│ ├── react16 // 子应用 react16 | ||
│ ├── react17 // 子应用 react17 | ||
│ ├── sidebar // 子应用 sidebar | ||
│ ├── vite // 子应用 vite | ||
│ ├── vue2 // 子应用 vue2 | ||
│ ├── vue3 // 子应用 vue3 | ||
│ ├── nextjs11 // 子应用 nextjs11,为每个基座应用单独打包,端口号:5001~5009 | ||
│ └── nuxtjs2 // 子应用 nuxtjs2,为每个基座应用单独打包,端口号:6001~6009 | ||
│ | ||
├── main-angular11 // 主应用 angular11 | ||
├── main-react16 // 主应用 react16 | ||
├── main-react17 // 主应用 react17 | ||
├── main-vite // 主应用 vite | ||
├── main-vue2 // 主应用 vue2 | ||
├── main-vue3 // 主应用 vue3 | ||
├── main-nextjs11 // 主应用 nextjs11,监听端口号:5000 | ||
├── main-nuxtjs2 // 主应用 nuxtjs2,监听端口号:7000 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
本篇介绍了vite2的接入方式,vite1暂不支持。 | ||
本篇介绍了`vite 2`的接入方式,vite1暂不支持。 | ||
|
||
## 作为基座应用 | ||
vite作为基座应用时没有特殊之处,具体方式参考各框架接入文档。 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
本篇以vue2、3作为案例介绍vue的接入方式,其它版本vue的接入方式以此类推,我们默认开发者掌握了各版本vue的开发技巧,比如示例中vue2的代码如何转换为vue1。 | ||
本篇以`Vue 2、3`作为案例介绍vue的接入方式,其它版本vue的接入方式以此类推,我们默认开发者掌握了各版本vue的开发技巧,比如示例中vue2的代码如何转换为vue1。 | ||
|
||
## 作为基座应用 | ||
我们强烈建议基座应用采用history模式,hash路由的基座应用只能加载hash路由的子应用,history模式的基座应用对这两种子应用都支持。 | ||
|
@@ -265,7 +265,7 @@ export default defineConfig({ | |
|
||
#### 3、当基座和子应用都是vue-router4,点击浏览器返回按钮页面丢失 | ||
|
||
**原因:**vue-router4没有对路由堆栈state做唯一性标记,导致基座和子应用相互影响,vue-router3及其它框架没有类似问题。 | ||
**原因:**vue-router4没有对路由堆栈state做唯一性标记,导致基座和子应用相互影响,vue-router3及其它框架路由没有类似问题。 | ||
|
||
**测试版本:**[email protected] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters