From 24952cf58011fcc365e95fe52a16d9f58db167ea Mon Sep 17 00:00:00 2001 From: Charles Riley Date: Tue, 17 Dec 2019 16:15:46 -0500 Subject: [PATCH 1/3] Add commit hash to static path --- .../react-scripts/config/webpack.config.js | 18 ++++++++++-------- packages/react-scripts/package.json | 10 +++++----- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index bad4290061b..f62d4461379 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -38,6 +38,8 @@ const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier'); // @remove-on-eject-end const postcssNormalize = require('postcss-normalize'); +const commit = require('child_process').execSync('git rev-parse --verify HEAD').toString().trim(); + const appPackageJson = require(paths.appPackageJson); // Source maps are resource heavy and can cause out of memory issue for large source files. @@ -184,14 +186,14 @@ module.exports = function(webpackEnv) { // There will be one main bundle, and one file per asynchronous chunk. // In development, it does not produce real files. filename: isEnvProduction - ? 'static/js/[name].[contenthash:8].js' - : isEnvDevelopment && 'static/js/bundle.js', + ? `static${commit}/js/[name].[contenthash:8].js` + : isEnvDevelopment && `static${commit}/js/bundle.js`, // TODO: remove this when upgrading to webpack 5 futureEmitAssets: true, // There are also additional JS chunk files if you use code splitting. chunkFilename: isEnvProduction - ? 'static/js/[name].[contenthash:8].chunk.js' - : isEnvDevelopment && 'static/js/[name].chunk.js', + ? `static${commit}/js/[name].[contenthash:8].chunk.js` + : isEnvDevelopment && `static${commit}/js/[name].chunk.js`, // We inferred the "public path" (such as / or /my-project) from homepage. // We use "/" in development. publicPath: publicPath, @@ -396,7 +398,7 @@ module.exports = function(webpackEnv) { loader: require.resolve('url-loader'), options: { limit: imageInlineSizeLimit, - name: 'static/media/[name].[hash:8].[ext]', + name: `static${commit}/media/[name].[hash:8].[ext]`, }, }, // Process application JS with Babel. @@ -570,7 +572,7 @@ module.exports = function(webpackEnv) { // by webpacks internal loaders. exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/], options: { - name: 'static/media/[name].[hash:8].[ext]', + name: `static${commit}/media/[name].[hash:8].[ext]`, }, }, // ** STOP ** Are you adding a new loader? @@ -644,8 +646,8 @@ module.exports = function(webpackEnv) { new MiniCssExtractPlugin({ // Options similar to the same options in webpackOptions.output // both options are optional - filename: 'static/css/[name].[contenthash:8].css', - chunkFilename: 'static/css/[name].[contenthash:8].chunk.css', + filename: `static${commit}/css/[name].[contenthash:8].css`, + chunkFilename: `static${commit}/css/[name].[contenthash:8].chunk.css`, }), // Generate an asset manifest file with the following content: // - "files" key: Mapping of all asset filenames to their corresponding diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index b70b184fe39..cb90bafcd7c 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -1,10 +1,10 @@ { - "name": "react-scripts", - "version": "3.3.0", - "description": "Configuration and scripts for Create React App.", + "name": "xometry-react-scripts", + "version": "3.3.1", + "description": "Xometry configuration and scripts for Create React App.", "repository": { "type": "git", - "url": "https://github.com/facebook/create-react-app.git", + "url": "https://github.com/xometry/create-react-app.git", "directory": "packages/react-scripts" }, "license": "MIT", @@ -12,7 +12,7 @@ "node": ">=8.10" }, "bugs": { - "url": "https://github.com/facebook/create-react-app/issues" + "url": "https://github.com/xometry/create-react-app/issues" }, "files": [ "bin", From facec8845ae0eb7dc86483cfd5133ab2fbabec22 Mon Sep 17 00:00:00 2001 From: Charles Riley Date: Wed, 18 Dec 2019 16:08:08 -0500 Subject: [PATCH 2/3] Use env var BUILD_ID --- .../react-scripts/config/webpack.config.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index f62d4461379..dfd76a58f7e 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -38,7 +38,7 @@ const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier'); // @remove-on-eject-end const postcssNormalize = require('postcss-normalize'); -const commit = require('child_process').execSync('git rev-parse --verify HEAD').toString().trim(); +const BUILD_ID = process.env.BUILD_ID || ''; const appPackageJson = require(paths.appPackageJson); @@ -186,14 +186,14 @@ module.exports = function(webpackEnv) { // There will be one main bundle, and one file per asynchronous chunk. // In development, it does not produce real files. filename: isEnvProduction - ? `static${commit}/js/[name].[contenthash:8].js` - : isEnvDevelopment && `static${commit}/js/bundle.js`, + ? `static-${BUILD_ID}/js/[name].[contenthash:8].js` + : isEnvDevelopment && `static-${BUILD_ID}/js/bundle.js`, // TODO: remove this when upgrading to webpack 5 futureEmitAssets: true, // There are also additional JS chunk files if you use code splitting. chunkFilename: isEnvProduction - ? `static${commit}/js/[name].[contenthash:8].chunk.js` - : isEnvDevelopment && `static${commit}/js/[name].chunk.js`, + ? `static-${BUILD_ID}/js/[name].[contenthash:8].chunk.js` + : isEnvDevelopment && `static-${BUILD_ID}/js/[name].chunk.js`, // We inferred the "public path" (such as / or /my-project) from homepage. // We use "/" in development. publicPath: publicPath, @@ -398,7 +398,7 @@ module.exports = function(webpackEnv) { loader: require.resolve('url-loader'), options: { limit: imageInlineSizeLimit, - name: `static${commit}/media/[name].[hash:8].[ext]`, + name: `static-${BUILD_ID}/media/[name].[hash:8].[ext]`, }, }, // Process application JS with Babel. @@ -572,7 +572,7 @@ module.exports = function(webpackEnv) { // by webpacks internal loaders. exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/], options: { - name: `static${commit}/media/[name].[hash:8].[ext]`, + name: `static-${BUILD_ID}/media/[name].[hash:8].[ext]`, }, }, // ** STOP ** Are you adding a new loader? @@ -646,8 +646,8 @@ module.exports = function(webpackEnv) { new MiniCssExtractPlugin({ // Options similar to the same options in webpackOptions.output // both options are optional - filename: `static${commit}/css/[name].[contenthash:8].css`, - chunkFilename: `static${commit}/css/[name].[contenthash:8].chunk.css`, + filename: `static-${BUILD_ID}/css/[name].[contenthash:8].css`, + chunkFilename: `static-${BUILD_ID}/css/[name].[contenthash:8].chunk.css`, }), // Generate an asset manifest file with the following content: // - "files" key: Mapping of all asset filenames to their corresponding From b1005267af81c8d275f86ded68cf0aa2bf08d66f Mon Sep 17 00:00:00 2001 From: Charles Riley Date: Wed, 18 Dec 2019 16:11:56 -0500 Subject: [PATCH 3/3] Use REACT_APP_BUILD_ID instead --- packages/react-scripts/config/webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index dfd76a58f7e..876f738bc4b 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -38,7 +38,7 @@ const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier'); // @remove-on-eject-end const postcssNormalize = require('postcss-normalize'); -const BUILD_ID = process.env.BUILD_ID || ''; +const BUILD_ID = process.env.REACT_APP_BUILD_ID || ''; const appPackageJson = require(paths.appPackageJson);