From 0081f766e5795ad8ba0c81f0454baf34b72c9ea5 Mon Sep 17 00:00:00 2001 From: Donald Hruska Date: Fri, 22 Jul 2016 14:15:30 -0500 Subject: [PATCH 1/5] Don't assume the project is hosted at the root * Require package.json in webpack.config.prod.js and use homepage if set; otherwise use '/' --- config/webpack.config.prod.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/config/webpack.config.prod.js b/config/webpack.config.prod.js index f372286a279..fd9def483a8 100644 --- a/config/webpack.config.prod.js +++ b/config/webpack.config.prod.js @@ -26,6 +26,7 @@ var nodeModulesPath = path.join(__dirname, '..', 'node_modules'); var indexHtmlPath = path.resolve(__dirname, relativePath, 'index.html'); var faviconPath = path.resolve(__dirname, relativePath, 'favicon.ico'); var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build'); +var publicPath = require('./package.json').homepage || '/'; module.exports = { bail: true, @@ -35,9 +36,7 @@ module.exports = { path: buildPath, filename: '[name].[chunkhash].js', chunkFilename: '[name].[chunkhash].chunk.js', - // TODO: this wouldn't work for e.g. GH Pages. - // Good news: we can infer it from package.json :-) - publicPath: '/' + publicPath: publicPath }, resolve: { extensions: ['', '.js'], From 17ced6bc9857181c67e4b737b0e0ff50173f3a01 Mon Sep 17 00:00:00 2001 From: Donald Hruska Date: Fri, 22 Jul 2016 19:23:53 -0500 Subject: [PATCH 2/5] Fix package.json path and add sample package.json for tests --- config/webpack.config.prod.js | 2 +- template/package.json | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 template/package.json diff --git a/config/webpack.config.prod.js b/config/webpack.config.prod.js index fd9def483a8..028e6c9e217 100644 --- a/config/webpack.config.prod.js +++ b/config/webpack.config.prod.js @@ -26,7 +26,7 @@ var nodeModulesPath = path.join(__dirname, '..', 'node_modules'); var indexHtmlPath = path.resolve(__dirname, relativePath, 'index.html'); var faviconPath = path.resolve(__dirname, relativePath, 'favicon.ico'); var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build'); -var publicPath = require('./package.json').homepage || '/'; +var publicPath = require(path.resolve(__dirname, relativePath, 'package.json')).homepage || '/'; module.exports = { bail: true, diff --git a/template/package.json b/template/package.json new file mode 100644 index 00000000000..e74146c7029 --- /dev/null +++ b/template/package.json @@ -0,0 +1,17 @@ +{ + "name": "my-app", + "version": "0.0.1", + "private": true, + "devDependencies": { + "react-scripts": "0.1.0" + }, + "dependencies": { + "react": "^15.2.1", + "react-dom": "^15.2.1" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "eject": "react-scripts eject" + } +} \ No newline at end of file From 24c9c9b9d677733bedf1727cd8400fd626d6f3c9 Mon Sep 17 00:00:00 2001 From: Donald Hruska Date: Sun, 24 Jul 2016 15:54:54 -0500 Subject: [PATCH 3/5] Update publicPath to use relative path portion of URL defined in homepage --- config/webpack.config.prod.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/webpack.config.prod.js b/config/webpack.config.prod.js index 028e6c9e217..1694705da6d 100644 --- a/config/webpack.config.prod.js +++ b/config/webpack.config.prod.js @@ -12,6 +12,7 @@ var autoprefixer = require('autoprefixer'); var webpack = require('webpack'); var HtmlWebpackPlugin = require('html-webpack-plugin'); var ExtractTextPlugin = require('extract-text-webpack-plugin'); +var url = require('url'); // TODO: hide this behind a flag and eliminate dead code on eject. // This shouldn't be exposed to the user. @@ -26,7 +27,8 @@ var nodeModulesPath = path.join(__dirname, '..', 'node_modules'); var indexHtmlPath = path.resolve(__dirname, relativePath, 'index.html'); var faviconPath = path.resolve(__dirname, relativePath, 'favicon.ico'); var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build'); -var publicPath = require(path.resolve(__dirname, relativePath, 'package.json')).homepage || '/'; +var homepagePath = require(path.resolve(__dirname, relativePath, 'package.json')).homepage; +var publicPath = homepagePath ? url.parse(homepagePath).pathname : '/'; module.exports = { bail: true, From e2dc775cd929f4615a6ffe92035edde124b40f5a Mon Sep 17 00:00:00 2001 From: Donald Hruska Date: Sun, 24 Jul 2016 16:21:13 -0500 Subject: [PATCH 4/5] Update successful bundle generation message --- scripts/build.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/scripts/build.js b/scripts/build.js index 6ac64886a75..f5299767a6e 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -28,12 +28,6 @@ webpack(config).run(function(err, stats) { var openCommand = process.platform === 'win32' ? 'start' : 'open'; console.log('Successfully generated a bundle in the build folder!'); - console.log(); - console.log('You can now serve it with any static server, for example:'); - console.log(' cd build'); - console.log(' npm install -g http-server'); - console.log(' hs'); - console.log(' ' + openCommand + ' http://localhost:8080'); - console.log(); + console.log('You can now deploy and serve it from .'); console.log('The bundle is optimized and ready to be deployed to production.'); }); From d16a09260602176b8ed2f460fa5accabf66c026d Mon Sep 17 00:00:00 2001 From: Donald Hruska Date: Sun, 24 Jul 2016 16:54:21 -0500 Subject: [PATCH 5/5] Show bundle generation success message based on presence of homepage in package.json --- scripts/build.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/build.js b/scripts/build.js index f5299767a6e..cfc194cace3 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -17,6 +17,9 @@ var config = require('../config/webpack.config.prod'); var isInNodeModules = 'node_modules' === path.basename(path.resolve(path.join(__dirname, '..', '..'))); var relative = isInNodeModules ? '../..' : '.'; +if (process.argv[2] === '--debug-template') { + relative = './template'; +} rimrafSync(relative + '/build'); webpack(config).run(function(err, stats) { @@ -27,7 +30,18 @@ webpack(config).run(function(err, stats) { } var openCommand = process.platform === 'win32' ? 'start' : 'open'; + var homepagePath = require(path.resolve(relative, 'package.json')).homepage; console.log('Successfully generated a bundle in the build folder!'); - console.log('You can now deploy and serve it from .'); + console.log(); + if (homepagePath) { + console.log('You can now deploy and serve it from ' + homepagePath + '.'); + } else { + console.log('You can now serve it with any static server, for example:'); + console.log(' cd build'); + console.log(' npm install -g http-server'); + console.log(' hs'); + console.log(' ' + openCommand + ' http://localhost:8080'); + } + console.log(); console.log('The bundle is optimized and ready to be deployed to production.'); });