Skip to content

Commit 49230f0

Browse files
committed
fix: #206
1 parent e14403e commit 49230f0

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

packages/crd-scripts/src/conf/getPrerenderRoutes.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const DirectoryTree = require('./node-directory-tree')
22

3-
// eg: ['docs/quick_start.md', 'a']
4-
// output: ['/quick_start', '/a/b', '/a/b/c']
5-
const getPrerenderRoutes = (cmd) => {
3+
const getDirTree = (cmd) => {
64
const dir = cmd.markdownPaths
75
const dirs = Array.isArray(dir) ? dir : [dir]
86
const otherProps = {
@@ -14,6 +12,12 @@ const getPrerenderRoutes = (cmd) => {
1412
path,
1513
options: otherProps,
1614
}))
15+
return dirTree
16+
}
17+
18+
// eg: ['docs/quick_start.md', 'a']
19+
// output: ['/quick_start', '/a/b', '/a/b/c']
20+
const getPrerenderRoutes = (dirTree) => {
1721
const result = getPrerenderRoute(dirTree)
1822
result.push('/404')
1923
return result
@@ -47,4 +51,7 @@ function recursive(data, routePath, arr) {
4751
return arr
4852
}
4953

50-
module.exports = getPrerenderRoutes
54+
module.exports = {
55+
getDirTree,
56+
getPrerenderRoutes
57+
}

packages/crd-scripts/src/conf/webpack.config.prod.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ const CopyMarkdownImageWebpackPlugin = require('copy-markdown-image-webpack-plug
77
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
88
const PrerenderSPAPlugin = require('crd-prerender-spa-plugin')
99
const { generateSiteMap } = require('crd-generator-sitemap')
10-
// const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
11-
// const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
1210
const fs = require('fs-extra')
1311
const { defaultHTMLPath, docsBuildDist } = require('crd-utils')
1412
const { getDocsConfig } = require('crd-utils')
1513
const config = require('./webpack.config')
1614
const paths = require('./path')
17-
const getPrerenderRoutes = require('./getPrerenderRoutes')
15+
const { getPrerenderRoutes, getDirTree } = require('./getPrerenderRoutes')
1816

1917
const Renderer = PrerenderSPAPlugin.PuppeteerRenderer
2018

2119
module.exports = function (cmd) {
2220
const docsConfig = getDocsConfig()
21+
const dirTree = getDirTree(cmd)
22+
const routes = getPrerenderRoutes(dirTree)
23+
console.log('dirTree', dirTree)
24+
2325
config.mode = 'production'
2426
config.entry = [paths.appIndexJs]
2527
// config.output.filename = 'js/[hash:8].js'
@@ -121,8 +123,6 @@ module.exports = function (cmd) {
121123
// ],
122124
}
123125

124-
const routes = getPrerenderRoutes(cmd)
125-
126126
config.plugins = config.plugins.concat([
127127
new webpack.DefinePlugin({
128128
env: JSON.stringify('prod'),
@@ -170,6 +170,11 @@ module.exports = function (cmd) {
170170
await fs.copy(`${docsBuildDist}/${docsConfig.repo}`, docsBuildDist)
171171
await fs.remove(`${docsBuildDist}/${docsConfig.repo}`)
172172
// move README as root index.html
173+
// todo: replace README with correct path
174+
175+
176+
177+
173178
await fs.copy(`${docsBuildDist}/README/index.html`, `${docsBuildDist}/index.html`)
174179
console.log('✅ generate prerender file success!')
175180
if (docsConfig.seo) {

0 commit comments

Comments
 (0)