Skip to content

Commit

Permalink
initial webpack externals support
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Aug 11, 2018
1 parent 0d089e2 commit 45d3f6a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/gatsby/src/utils/html-renderer-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ module.exports = (htmlComponentRendererPath, pages, activity) =>
pageSegment =>
new Promise((resolve, reject) => {
workerPool
.renderHTML({ htmlComponentRendererPath, paths: pageSegment })
.renderHTML({
htmlComponentRendererPath,
paths: pageSegment,
envVars: {
NODE_ENV: process.env.NODE_ENV,
gatsby_executing_command: process.env.gatsby_executing_command,
gatsby_log_level: process.env.gatsby_log_level,
},
})
.then(() => {
finished += pageSegment.length
if (activity) {
Expand Down
43 changes: 43 additions & 0 deletions packages/gatsby/src/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,49 @@ module.exports = async (
}
}

if (stage === `build-html` || stage === `develop-html`) {
const externalList = [
/^lodash/,
`react`,
/^react-dom/,
`pify`,
`@reach/router`,
`@reach/router/lib/history`,
`common-tags`,
`path`,
`semver`,
`react-helmet`,
`minimatch`,
`fs`,
/^core-js/,
`es6-promise`,
`crypto`,
`zlib`,
`http`,
`https`,
`debug`,
]

config.externals = [
function(context, request, callback) {
if (
externalList.some(item => {
if (typeof item === `string` && item === request) {
return true
} else if (item instanceof RegExp && item.test(request)) {
return true
}

return false
})
) {
return callback(null, `umd ${request}`)
}
return callback()
},
]
}

store.dispatch(actions.replaceWebpackConfig(config))
const getConfig = () => store.getState().webpack

Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby/src/utils/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ const generatePathToOutput = outputPath => {
return path.join(process.cwd(), `public`, outputFileName)
}

export function renderHTML({ htmlComponentRendererPath, paths }) {
export function renderHTML({ htmlComponentRendererPath, paths, envVars }) {
// This is being executed in child process, so we need to set some vars
// for modules that aren't bundled by webpack.
Object.entries(envVars).forEach(([key, value]) => (process.env[key] = value))

return Promise.map(
paths,
path =>
Expand Down

0 comments on commit 45d3f6a

Please sign in to comment.