This commit is contained in:
winixt 2021-11-16 16:36:40 +08:00
commit a9813c8c91
8 changed files with 61 additions and 9 deletions

View File

@ -45,7 +45,7 @@ export default {
};
```
```js
// src/locales/zh-CN.js
// src/locales/en-US.js
export default {
menu: {
interface: 'interface'
@ -199,4 +199,4 @@ export default {
</script>
```
`useI18n()`返回结果是 [Composer](https://vue-i18n.intlify.dev/api/composition.html#composer),提供类似 `t`、`n`、`d` 等转换函数,在模板中使用。
`useI18n()`返回结果是 [Composer](https://vue-i18n.intlify.dev/api/composition.html#composer),提供类似 `t`、`n`、`d` 等转换函数,在模板中使用。

View File

@ -45,8 +45,10 @@ export default function () {
require.resolve('./plugins/features/mock'),
require.resolve('./plugins/features/dynamicImport'),
require.resolve('./plugins/features/runtimePublicPath'),
require.resolve('./plugins/features/exportStatic'),
require.resolve('./plugins/features/checkVuePackage'),
// misc
require.resolve('./plugins/misc/route'),

View File

@ -73,7 +73,7 @@ export async function getBundleAndConfigs({
const bundleConfig = await api.applyPlugins({
type: api.ApplyPluginsType.modify,
key: 'modifyBundleConfig',
initialValue: await getConfig(getConfigOpts),
initialValue: await getConfig({ api, ...getConfigOpts }),
args: {
}
});

View File

@ -6,6 +6,7 @@ import {
import resolveDefine from './resolveDefine';
export default async function createHtmlWebpackConfig({
api,
cwd,
config,
webpackConfig,
@ -38,13 +39,14 @@ export default async function createHtmlWebpackConfig({
const defaultHtmlPath = resolve(__dirname, 'index-default.html');
const publicCopyIgnore = [];
if (!multiPageConfig) {
// default, single page setup.
htmlOptions.template = existsSync(htmlPath)
? htmlPath
: defaultHtmlPath;
// default, single page setup.
htmlOptions.template = existsSync(htmlPath)
? htmlPath
: defaultHtmlPath;
publicCopyIgnore.push(winPath(htmlOptions.template));
publicCopyIgnore.push(winPath(htmlOptions.template));
if (!multiPageConfig) {
webpackConfig
.plugin('html')
.use(require.resolve('html-webpack-plugin'), [htmlOptions]);
@ -52,6 +54,34 @@ export default async function createHtmlWebpackConfig({
// TODO 支持多页
}
// 如果需要导出html则根据路由生成对应的html文件
if (config.exportStatic) {
const routes = await api.getRoutes();
const addHtml = (_routes) => {
if (Array.isArray(_routes)) {
_routes.forEach((route) => {
const _fileName = `${route.path.slice(1) || 'index'}.html`;
if (_fileName !== 'index.html') {
const _htmlOptions = {
...config.html,
title: route?.meta?.title || config.html.title || 'fes.js',
filename: _fileName,
templateParameters: resolveDefine(config, true),
mountElementId: config.mountElementId
};
webpackConfig
.plugin(_fileName)
.use(require.resolve('html-webpack-plugin'), [_htmlOptions]);
}
if (route.children && route.children.length) {
addHtml(route.children);
}
});
}
};
addHtml(routes);
}
if (headScripts) {
const headScriptsMap = await headScripts();
webpackConfig

View File

@ -59,6 +59,7 @@ function genTranspileDepRegex(exclude) {
export default async function getConfig({
api,
cwd,
config,
env,
@ -221,6 +222,7 @@ export default async function getConfig({
// --------------- html -----------
const { publicCopyIgnore } = await createHtmlWebpackConfig({
api,
cwd,
config,
webpackConfig,

View File

@ -1,10 +1,12 @@
// .fes.js 只负责管理编译时配置只能使用plain Object
export default {
exportStatic: {},
base: "/base/",
define: {
__DEV__: false,
},
publicPath: "./",
html: {
title: "海贼王",
},

View File

@ -0,0 +1,8 @@
<template>
<div>a/b</div>
</template>
<script>
export default {
};
</script>

View File

@ -0,0 +1,8 @@
<template>
<div>b</div>
</template>
<script>
export default {
};
</script>