Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate linkPrefix into webpack's publicPath #502

Merged
merged 1 commit into from
Oct 25, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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