Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit cd148a2

Browse files
committed
fix(module): properly detect static mode (nuxt generate)
Properly set `axios` baseUrl accordingly Properly trigger static routes generation in content builder accordingly fixes #83, #88, #89
1 parent 165dde1 commit cd148a2

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

lib/content/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const addAssets = (nuxtOpts, assetMap) => {
8282
* 1) Add content data to assets so that it can be statically requested.
8383
* 2) Adds dynamic content routes to nuxt generate so that pages can get built.
8484
*/
85-
const buildContent = (nuxt, buildDir, options) => {
85+
const buildContent = (nuxt, buildDir, isStatic, options) => {
8686
const { contentDir, content, parsers, isDev } = options
8787

8888
const routePages = [] // dynamic pages to create
@@ -98,7 +98,7 @@ const buildContent = (nuxt, buildDir, options) => {
9898
routePaths.set(name, permalink.replace(/^\//, ''))
9999
}
100100

101-
if (generate && process.env.STATIC) {
101+
if (generate && isStatic) {
102102
const dirOpts = { ...content[dirName], parsers }
103103
const db = createDatabase(contentDir, dirName, dirOpts, isDev)
104104

lib/module.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export default function ContentModule(moduleOpts) {
6464
const contentDirWebpackAlias = '~/' + CONTENT_DIR
6565
const port =
6666
process.env.PORT || process.env.npm_package_config_nuxt_port || 3000
67+
6768
const isDev = this.nuxt.options.dev
6869
const loaderComponentExtensions = ['.vue', '.js']
6970

@@ -115,8 +116,25 @@ export default function ContentModule(moduleOpts) {
115116
})
116117
})
117118

118-
// 2. Build dynamic content pages without components (*.md)
119-
buildContent(this, BUILD_DIR, routesOptions)
119+
this.nuxt.plugin('build', builder => {
120+
// 1. Initialize axios module
121+
this.requireModule([
122+
'@nuxtjs/axios',
123+
{
124+
baseURL: api.baseURL + api.serverPrefix,
125+
browserBaseURL:
126+
api.baseURL +
127+
(builder.isStatic ? api.browserPrefix : api.serverPrefix)
128+
}
129+
])
130+
131+
// 2. Build dynamic content pages without components (*.md)
132+
buildContent(this, BUILD_DIR, builder.isStatic, routesOptions)
133+
})
134+
135+
this.addPlugin({
136+
src: resolve(__dirname, 'plugins/requestContent.js')
137+
})
120138

121139
// 3. Add content API
122140
const router = createRouter(api, routesOptions)
@@ -138,22 +156,7 @@ export default function ContentModule(moduleOpts) {
138156
})
139157
})
140158

141-
// 4. Add request helpers
142-
this.requireModule([
143-
'@nuxtjs/axios',
144-
{
145-
baseURL: api.baseURL + api.serverPrefix,
146-
browserBaseURL:
147-
api.baseURL +
148-
(process.env.STATIC ? api.browserPrefix : api.serverPrefix)
149-
}
150-
])
151-
152-
this.addPlugin({
153-
src: resolve(__dirname, 'plugins/requestContent.js')
154-
})
155-
156-
// 5. Add Vue templates generated from markdown to output build
159+
// 4. Add Vue templates generated from markdown to output build
157160
this.addPlugin({
158161
src: resolve(__dirname, 'plugins/markdownComponents.template.js'),
159162
options: {

0 commit comments

Comments
 (0)