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

Commit

Permalink
fix(module): properly detect static mode (nuxt generate)
Browse files Browse the repository at this point in the history
Properly set `axios` baseUrl accordingly
Properly trigger static routes generation in content builder accordingly

fixes #83, #88, #89
  • Loading branch information
medfreeman committed Sep 29, 2017
1 parent 165dde1 commit cd148a2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lib/content/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const addAssets = (nuxtOpts, assetMap) => {
* 1) Add content data to assets so that it can be statically requested.
* 2) Adds dynamic content routes to nuxt generate so that pages can get built.
*/
const buildContent = (nuxt, buildDir, options) => {
const buildContent = (nuxt, buildDir, isStatic, options) => {
const { contentDir, content, parsers, isDev } = options

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

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

Expand Down
39 changes: 21 additions & 18 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default function ContentModule(moduleOpts) {
const contentDirWebpackAlias = '~/' + CONTENT_DIR
const port =
process.env.PORT || process.env.npm_package_config_nuxt_port || 3000

const isDev = this.nuxt.options.dev
const loaderComponentExtensions = ['.vue', '.js']

Expand Down Expand Up @@ -115,8 +116,25 @@ export default function ContentModule(moduleOpts) {
})
})

// 2. Build dynamic content pages without components (*.md)
buildContent(this, BUILD_DIR, routesOptions)
this.nuxt.plugin('build', builder => {
// 1. Initialize axios module
this.requireModule([
'@nuxtjs/axios',
{
baseURL: api.baseURL + api.serverPrefix,
browserBaseURL:
api.baseURL +
(builder.isStatic ? api.browserPrefix : api.serverPrefix)
}
])

// 2. Build dynamic content pages without components (*.md)
buildContent(this, BUILD_DIR, builder.isStatic, routesOptions)
})

this.addPlugin({
src: resolve(__dirname, 'plugins/requestContent.js')
})

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

// 4. Add request helpers
this.requireModule([
'@nuxtjs/axios',
{
baseURL: api.baseURL + api.serverPrefix,
browserBaseURL:
api.baseURL +
(process.env.STATIC ? api.browserPrefix : api.serverPrefix)
}
])

this.addPlugin({
src: resolve(__dirname, 'plugins/requestContent.js')
})

// 5. Add Vue templates generated from markdown to output build
// 4. Add Vue templates generated from markdown to output build
this.addPlugin({
src: resolve(__dirname, 'plugins/markdownComponents.template.js'),
options: {
Expand Down

0 comments on commit cd148a2

Please sign in to comment.