Skip to content

Commit

Permalink
Merge pull request #533 from gatsbyjs/add-recordsPath
Browse files Browse the repository at this point in the history
Add recordsPath to Webpack so module IDs are consistent across builds
  • Loading branch information
KyleAMathews authored Nov 1, 2016
2 parents 70547a3 + 51ae142 commit f25522d
Show file tree
Hide file tree
Showing 5 changed files with 495 additions and 195 deletions.
18 changes: 16 additions & 2 deletions lib/intermediate-representation-dir/production-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,22 @@ try {

// Install service worker.
runtime.install({
onInstalled () {
console.log(`App is ready for offline usage`)
onInstalled: () => {
console.log("SW Event:", "onInstalled")
},
onUpdating: () => {
console.log("SW Event:", "onUpdating")
},
onUpdateReady: () => {
console.log("SW Event:", "onUpdateReady")
runtime.applyUpdate()
},
onUpdated: () => {
console.log("SW Event:", "onUpdated")
apiRunner('swOnUpdated')
},
onUninstalled: () => {
console.log("SW Event:", "onUninstalled")
},
})

Expand Down
15 changes: 9 additions & 6 deletions lib/utils/serve-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,26 @@ function startServer (program, launchPort) {
}

module.exports = (program) => {
detect(program.port, (err, _port) => {
const port = typeof program.port === 'string'
? parseInt(program.port, 10)
: program.port

detect(port, (err, _port) => {
if (err) {
console.error(err)
process.exit()
}

if (program.port !== _port) {
if (port !== _port) {
// eslint-disable-next-line max-len
const question = `Something is already running at port ${program.port} \nWould you like to run the app at another port instead? [Y/n] `
const question = `Something is already running at port ${port} \nWould you like to run the app at another port instead? [Y/n] `

return rlInterface.question(question, (answer) => {
let launchPort = program.port
if (answer.length === 0 || answer.match(/^yes|y$/i)) {
launchPort = _port
program.port = _port
}

return startServer(program, launchPort)
return startServer(program, program.port)
})
}

Expand Down
9 changes: 5 additions & 4 deletions lib/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,13 @@ module.exports = (program, directory, suppliedStage, webpackPort = 1500, pages =
__PREFIX_LINKS__: program.prefixLinks,
__LINK_PREFIX__: JSON.stringify(siteDB().get(`config`).linkPrefix),
}),
// Names module ids with their filepath. We use this in development
// to make it easier to see what modules have hot reloaded, etc. as
// the numerical IDs aren't useful. In production we use numerical module
// ids to reduce filesize.
new webpack.NamedModulesPlugin(),
new HardSourceWebpackPlugin({
cacheDirectory: `${process.cwd()}/.cache/[confighash]`,
recordsPath: `${process.cwd()}/.cache/[confighash]/records.json`,
configHash: (webpackConfig) => stage,
environmentPaths: {
root: process.cwd(),
Expand All @@ -134,7 +137,6 @@ module.exports = (program, directory, suppliedStage, webpackPort = 1500, pages =
new ExtractTextPlugin(`styles.css`, { allChunks: true }),
new HardSourceWebpackPlugin({
cacheDirectory: `${process.cwd()}/.cache/[confighash]`,
recordsPath: `${process.cwd()}/.cache/[confighash]/records.json`,
configHash: (webpackConfig) => stage,
environmentPaths: {
root: process.cwd(),
Expand All @@ -156,7 +158,6 @@ module.exports = (program, directory, suppliedStage, webpackPort = 1500, pages =
new ExtractTextPlugin(`build-html-styles.css`),
new HardSourceWebpackPlugin({
cacheDirectory: `${process.cwd()}/.cache/[confighash]`,
recordsPath: `${process.cwd()}/.cache/[confighash]/records.json`,
configHash: (webpackConfig) => stage,
environmentPaths: {
root: process.cwd(),
Expand Down Expand Up @@ -249,7 +250,6 @@ module.exports = (program, directory, suppliedStage, webpackPort = 1500, pages =
}),
new HardSourceWebpackPlugin({
cacheDirectory: `${process.cwd()}/.cache/[confighash]`,
recordsPath: `${process.cwd()}/.cache/[confighash]/records.json`,
configHash: (webpackConfig) => stage,
environmentPaths: {
root: process.cwd(),
Expand Down Expand Up @@ -497,6 +497,7 @@ module.exports = (program, directory, suppliedStage, webpackPort = 1500, pages =
resolveLoader: resolveLoader(),
plugins: plugins(),
resolve: resolve(),
recordsPath: `${process.cwd()}/.webpack-records/records-${stage}.json`,
})

return webpackModifyValidate(module, config, stage)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"css-loader": "^0.25.0",
"debug": "^2.2.0",
"detect-port": "^1.0.5",
"eslint-plugin-import": "^1.16.0",
"excerpt-html": "^1.1.1",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.9.0",
Expand All @@ -64,6 +63,7 @@
"loader-utils": "^0.2.16",
"lodash": "^4.16.5",
"markdown-it": "^7.0.1",
"md5-file": "^3.1.1",
"mkdirp": "^0.5.1",
"moment": "^2.15.2",
"negotiator": "^0.6.1",
Expand Down Expand Up @@ -124,7 +124,7 @@
"eslint-config-airbnb": "^12.0.0",
"eslint-plugin-flow-vars": "^0.5.0",
"eslint-plugin-flowtype": "^2.25.0",
"eslint-plugin-import": "^2.0.1",
"eslint-plugin-import": "^1.16.0",
"eslint-plugin-jsx-a11y": "^2.2.2",
"eslint-plugin-react": "^6.3.0",
"flow-bin": "^0.34.0",
Expand Down
Loading

0 comments on commit f25522d

Please sign in to comment.