Skip to content

Commit

Permalink
Incorporate linkPrefix into webpack's publicPath
Browse files Browse the repository at this point in the history
This correctly references asset paths, e.g. FontAwesome, when static
sites are targeted at sub-paths.
  • Loading branch information
mojodna committed Oct 24, 2016
1 parent 37944c5 commit 654b87e
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import StaticSiteGeneratorPlugin from 'static-site-generator-webpack-plugin'
import ExtractTextPlugin from 'extract-text-webpack-plugin'
import Config from 'webpack-configurator'
const debug = require('debug')('gatsby:webpack-config')
import fs from 'fs'
import path from 'path'
import _ from 'lodash'
import invariant from 'invariant'
import toml from 'toml'

import babelConfig from './babel-config'

Expand All @@ -31,8 +33,28 @@ module.exports = (program, directory, suppliedStage, webpackPort = 1500, routes
const babelStage = suppliedStage
const stage = (suppliedStage === 'develop-html') ? 'develop' : suppliedStage

let siteConfig = {}

try {
siteConfig = toml.parse(fs.readFileSync(path.join(directory, 'config.toml')))
} catch (e) {
if (e.code !== 'ENOENT') {
throw e
}
}

debug(`Loading webpack config for stage "${stage}"`)
function output () {
let publicPath = '/'

if (program.prefixLinks) {
publicPath = siteConfig.linkPrefix

if (!publicPath.endsWith('/')) {
publicPath += '/'
}
}

switch (stage) {
case 'develop':
return {
Expand All @@ -46,7 +68,7 @@ module.exports = (program, directory, suppliedStage, webpackPort = 1500, routes
return {
path: `${directory}/public`,
filename: 'bundle-for-css.js',
publicPath: '/',
publicPath,
}
case 'build-html':
// A temp file required by static-site-generator-plugin. See plugins() below.
Expand All @@ -55,11 +77,13 @@ module.exports = (program, directory, suppliedStage, webpackPort = 1500, routes
path: `${directory}/public`,
filename: 'render-page.js',
libraryTarget: 'umd',
publicPath,
}
case 'build-javascript':
return {
filename: 'bundle.js',
path: `${directory}/public`,
publicPath,
}
default:
throw new Error(`The state requested ${stage} doesn't exist.`)
Expand Down

0 comments on commit 654b87e

Please sign in to comment.