Skip to content

Commit 65e8cac

Browse files
committed
Add setting page title config.
1 parent 4c3fafd commit 65e8cac

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

src/conf/webpack.config.dev.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
66
const CreateSpareWebpackPlugin = require('create-spare-webpack-plugin');
77
const FriendlyErrorsWebpackPlugin = require('@nuxtjs/friendly-errors-webpack-plugin');
88
const config = require('./webpack.config');
9-
const pkg = require('../../package.json');
109
const paths = require('./path');
1110

1211
module.exports = function (cmd) {
@@ -16,11 +15,6 @@ module.exports = function (cmd) {
1615
require.resolve('webpack-hot-dev-clients/webpackHotDevClient'),
1716
paths.appIndexJs,
1817
];
19-
config.resolve = {
20-
alias: {
21-
'rdoc-theme': UPATH.normalizeSafe(paths.appThemePath),
22-
},
23-
};
2418
config.module.rules = config.module.rules.map((item) => {
2519
if (item.oneOf) {
2620
const loaders = [];
@@ -111,9 +105,7 @@ module.exports = function (cmd) {
111105
inject: true,
112106
favicon: paths.defaultFaviconPath,
113107
template: paths.defaultHTMLPath,
114-
}),
115-
new webpack.DefinePlugin({
116-
VERSION: JSON.stringify(pkg.version),
108+
title: paths.rdocConf && paths.rdocConf.title ? paths.rdocConf.title : 'Rdoc',
117109
}),
118110
// 将模块名称添加到工厂功能,以便它们显示在浏览器分析器中。
119111
// 当接收到热更新信号时,在浏览器console控制台打印更多可读性高的模块名称等信息

src/conf/webpack.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const PATH = require('path');
2+
const webpack = require('webpack');
3+
const UPATH = require('upath');
24
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
35
const paths = require('./path');
6+
const pkg = require('../../package.json');
47

58
module.exports = {
69
entry: {},
@@ -10,6 +13,11 @@ module.exports = {
1013
filename: 'js/[name].[hash:8].js',
1114
chunkFilename: 'js/[name].[hash:8].js',
1215
},
16+
resolve: {
17+
alias: {
18+
'rdoc-theme': UPATH.normalizeSafe(paths.appThemePath),
19+
},
20+
},
1321
module: {
1422
rules: [
1523
{
@@ -84,6 +92,9 @@ module.exports = {
8492
format: ` build [:bar] ${':percent'.green} (:elapsed seconds)`,
8593
clear: false,
8694
}),
95+
new webpack.DefinePlugin({
96+
VERSION: JSON.stringify(pkg.version),
97+
}),
8798
],
8899
node: {
89100
dgram: 'empty',

src/conf/webpack.config.prod.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const autoprefixer = require('autoprefixer');
2-
const webpack = require('webpack');
32
const PATH = require('path');
43
const UPATH = require('upath');
54
const HtmlWebpackPlugin = require('html-webpack-plugin');
@@ -9,19 +8,13 @@ const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
98
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
109
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
1110
const config = require('./webpack.config');
12-
const pkg = require('../../package.json');
1311
const paths = require('./path');
1412

1513
module.exports = function (cmd) {
1614
config.mode = 'production';
1715
config.entry = [paths.appIndexJs];
1816
config.output.filename = 'js/[hash:8].js';
1917
config.output.chunkFilename = 'js/[name].[hash:8].js';
20-
config.resolve = {
21-
alias: {
22-
'rdoc-theme': UPATH.normalizeSafe(paths.appThemePath),
23-
},
24-
};
2518
config.module.rules = config.module.rules.map((item) => {
2619
if (item.oneOf) {
2720
const loaders = [];
@@ -141,6 +134,7 @@ module.exports = function (cmd) {
141134
inject: true,
142135
favicon: paths.defaultFaviconPath,
143136
template: paths.defaultHTMLPath,
137+
title: paths.rdocConf && paths.rdocConf.title ? paths.rdocConf.title : 'Rdoc',
144138
minify: {
145139
removeAttributeQuotes: true,
146140
collapseWhitespace: true,
@@ -150,9 +144,6 @@ module.exports = function (cmd) {
150144
removeEmptyAttributes: true,
151145
},
152146
}),
153-
new webpack.DefinePlugin({
154-
VERSION: JSON.stringify(pkg.version),
155-
}),
156147
new CopyMarkdownImageWebpackPlugin({
157148
dir: cmd.markdownPaths,
158149
toDir: config.output.path,

templates/default/introduce/api/conf.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ sort: 4
4242

4343
```json
4444
{
45+
"title": "Rdoc title",
4546
"theme": "rdoc-theme-load-react",
4647
"favicon": "./assets/favicon.ico",
4748
"logo": "./assets/rdoc.logo.svg",
@@ -55,6 +56,14 @@ sort: 4
5556
1. 优先读取 `.rdocrc.json` 配置。
5657
2. 两种配置只有一种起作用。
5758

59+
### title
60+
61+
设置默认网页标题内容。
62+
63+
```html
64+
<title>Rdoc title</title>
65+
```
66+
5867
### favicon
5968

6069
默认显示 `rdoc` 的图标,自定义 `favicon` 需要自己生成一个图标命名为 `favicon.ico` 放在项目的根目录自动识别。添加配置,可以指定不同文件名和路径下的 `ico` 文件。

theme/default/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html xmlns="http://www.w3.org/1999/xhtml">
33

44
<head>
5-
<title>RDoc</title>
5+
<title><%= htmlWebpackPlugin.options.title %></title>
66
<meta charset="utf-8">
77
<meta http-equiv="X-UA-Compatible" content="IE=edge">
88
<meta name="viewport" content="width=device-width, initial-scale=1.0">

0 commit comments

Comments
 (0)