Skip to content

Commit

Permalink
[WIP] Generate an hash for cache bypassing between builds (#291)
Browse files Browse the repository at this point in the history
As things can get pretty complex while explaining, gonna apply here
things proposed over this branch.
  • Loading branch information
José Moreira committed May 20, 2016
1 parent cb9d686 commit 9f24b14
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import _ from 'lodash'

import babelConfig from './babel-config'

// Generate an hash for cache bypassing between builds (#291)
const ASSETS_CACHE = (+new Date()).toString(32)

let modifyWebpackConfig
try {
const gatsbyNodeConfig = path.resolve(process.cwd(), './gatsby-node')
Expand Down Expand Up @@ -39,21 +42,21 @@ module.exports = (program, directory, stage, webpackPort = 1500, routes = []) =>
// Webpack will always generate a resultant javascript file.
// But we don't want it for this step. Deleted by build-css.js.
return {
path: `${directory}/public`,
filename: 'bundle-for-css.js',
path: `${directory}/public/${ASSETS_CACHE}`,
}
case 'build-html':
// A temp file required by static-site-generator-plugin. See plugins() below.
// Deleted by build-html.js, since it's not needed for production.
return {
path: `${directory}/public`,
filename: 'render-page.js',
path: `${directory}/public`,
libraryTarget: 'umd',
}
case 'build-javascript':
return {
filename: 'bundle.js',
path: `${directory}/public`,
path: `${directory}/public/${ASSETS_CACHE}`,
}
default:
throw new Error(`The state requested ${stage} doesn't exist.`)
Expand Down Expand Up @@ -103,6 +106,7 @@ module.exports = (program, directory, stage, webpackPort = 1500, routes = []) =>
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV ? process.env.NODE_ENV : 'production'),
ASSETS_CACHE: JSON.stringify( ASSETS_CACHE ),
},
__PREFIX_LINKS__: program.prefixLinks,
}),
Expand All @@ -114,7 +118,8 @@ module.exports = (program, directory, stage, webpackPort = 1500, routes = []) =>
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV ? process.env.NODE_ENV : 'production'),
},
ASSETS_CACHE: JSON.stringify( ASSETS_CACHE ),
},
__PREFIX_LINKS__: program.prefixLinks,
}),
]
Expand All @@ -127,6 +132,7 @@ module.exports = (program, directory, stage, webpackPort = 1500, routes = []) =>
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV ? process.env.NODE_ENV : 'production'),
ASSETS_CACHE: JSON.stringify( ASSETS_CACHE ),
},
__PREFIX_LINKS__: program.prefixLinks,
}),
Expand Down

0 comments on commit 9f24b14

Please # to comment.