From 81cf8cbd7cf7281d7bbeb9ef4afeec1f7e5a62bf Mon Sep 17 00:00:00 2001 From: dannyrb Date: Tue, 30 Apr 2019 13:36:25 -0400 Subject: [PATCH 1/3] Set ENV variables in scripts instead of in build --- .env.example | 13 +++++++++++++ .env.production | 14 -------------- .../deployment/recipes/build-for-production.md | 9 ++++++--- package.json | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 .env.example delete mode 100644 .env.production diff --git a/.env.example b/.env.example new file mode 100644 index 000000000..d179308f1 --- /dev/null +++ b/.env.example @@ -0,0 +1,13 @@ +## +# EXAMPLE +# +# Read more about .env files when using create-react-app here: +# https://facebook.github.io/create-react-app/docs/adding-custom-environment-variables#adding-development-environment-variables-in-env +# + +PUBLIC_URL=/demo + +# +# Most vars require REACT_APP_* naming +# +REACT_APP_CONFIG=config/netlify.js diff --git a/.env.production b/.env.production deleted file mode 100644 index 464ee6dc5..000000000 --- a/.env.production +++ /dev/null @@ -1,14 +0,0 @@ -## -# PRODUCTION: Netlify -# -# We're using this to set variables for our Netlify deploy. -# Please feel free to delete or modify this file for your own production -# environment. Be careful not to commit anything sensitive to source control. -# - -PUBLIC_URL=/demo - -# -# Most vars require REACT_APP_* naming -# -REACT_APP_CONFIG=config/netlify.js diff --git a/docs/latest/deployment/recipes/build-for-production.md b/docs/latest/deployment/recipes/build-for-production.md index 6ab01c731..20864d125 100644 --- a/docs/latest/deployment/recipes/build-for-production.md +++ b/docs/latest/deployment/recipes/build-for-production.md @@ -70,15 +70,18 @@ how to configure the project for your own imaging archive below. > ["Set up a local DICOM server"](./../../essentials/getting-started.md#set-up-a-local-dicom-server), > or a deployment recipe that contains an open source Image Archive -#### How It Works +#### How it Works The configuration for our project is in the `/public/config` directory. Our build process knows which configuration file to use based on the `REACT_APP_CONFIG` environment variable. By default, its value is [`default.js`](https://github.com/OHIF/Viewers/blob/react/public/config/default.js). When we build, the `%REACT_APP_CONFIG%` value in -our[`/public/index.html`](https://github.com/OHIF/Viewers/blob/react/public/index.html#L12-L15)`file is substituted for the correct configuration file's name. Ultimately setting the`window.config` -equal to our configuration file's value. +our[`/public/index.html`](https://github.com/OHIF/Viewers/blob/react/public/index.html#L12-L15) +file is substituted for the correct configuration file's name. This sets +the`window.config` equal to our configuration file's value. + +#### How do I configure my project? - Modify its values directly - Create a new config file, and set the `REACT_APP_CONFIG` environement variable diff --git a/package.json b/package.json index 68929a2ae..dd2e7978c 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "build:package": "yarn run preBuild && node --max-old-space-size=4096 node_modules/rollup/bin/rollup -c", "build:package:ci": "yarn run preBuild && cross-env REACT_APP_CONFIG=config/default.js node --max-old-space-size=4096 node_modules/rollup/bin/rollup -c", "build:web": "yarn run preBuild && react-scripts --max_old_space_size=4096 build", - "build:web:ci": "yarn run preBuild && react-scripts --max_old_space_size=4096 build && cpx 'build/**/*' docs/latest/_book/demo --verbose", + "build:web:ci": "yarn run preBuild && cross-env PUBLIC_URL=/demo REACT_APP_CONFIG=config/netlify.js react-scripts --max_old_space_size=4096 build && cpx 'build/**/*' docs/latest/_book/demo --verbose", "lint": "eslint -c .eslintrc --fix src && prettier --single-quote --write src/**/*.{js,jsx,json,css}", "test": "jest", "test:ci": "jest --ci --runInBand --collectCoverage --reporters=default --reporters=jest-junit && codecov", From 4cecdcc3dccf58ff12fbb36f2b69329e13586d40 Mon Sep 17 00:00:00 2001 From: dannyrb Date: Tue, 30 Apr 2019 13:37:28 -0400 Subject: [PATCH 2/3] Defaults --- .env.development => .env | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename .env.development => .env (73%) diff --git a/.env.development b/.env similarity index 73% rename from .env.development rename to .env index 062b97107..6f5a2f3bd 100644 --- a/.env.development +++ b/.env @@ -1,7 +1,7 @@ ## -# DEVELOPMENT: Default +# Environment: Default # -# We're using this to set variables for our local development. +# We're using this to set variables for development. # Please feel free to delete or modify this file for your own setup. # Be careful not to commit anything sensitive to source control. # From 686f613fd0799c323b6d6510d053c43a64b46b8f Mon Sep 17 00:00:00 2001 From: dannyrb Date: Tue, 30 Apr 2019 16:11:06 -0400 Subject: [PATCH 3/3] Use absolute path for webworker scripts --- package.json | 2 +- src/utils/initWebWorkers.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index dd2e7978c..2e98caa5c 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "dev": "yarn run preBuild && cross-env PORT=5000 react-scripts start", "dev:debug": "cross-env PORT=5000 react-scripts start", "build:package": "yarn run preBuild && node --max-old-space-size=4096 node_modules/rollup/bin/rollup -c", - "build:package:ci": "yarn run preBuild && cross-env REACT_APP_CONFIG=config/default.js node --max-old-space-size=4096 node_modules/rollup/bin/rollup -c", + "build:package:ci": "yarn run preBuild && node --max-old-space-size=4096 node_modules/rollup/bin/rollup -c", "build:web": "yarn run preBuild && react-scripts --max_old_space_size=4096 build", "build:web:ci": "yarn run preBuild && cross-env PUBLIC_URL=/demo REACT_APP_CONFIG=config/netlify.js react-scripts --max_old_space_size=4096 build && cpx 'build/**/*' docs/latest/_book/demo --verbose", "lint": "eslint -c .eslintrc --fix src && prettier --single-quote --write src/**/*.{js,jsx,json,css}", diff --git a/src/utils/initWebWorkers.js b/src/utils/initWebWorkers.js index 1de094071..26ec6ca2b 100644 --- a/src/utils/initWebWorkers.js +++ b/src/utils/initWebWorkers.js @@ -6,7 +6,9 @@ import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader' * @param {String} webWorkScriptsPath */ export default function(baseDirectory, webWorkScriptsPath) { - const scriptsPath = `${baseDirectory}/${webWorkScriptsPath}` + const scriptsPath = `${window.location.protocol}//${ + window.location.host + }${baseDirectory}/${webWorkScriptsPath}` const config = { maxWebWorkers: Math.max(navigator.hardwareConcurrency - 1, 1), startWebWorkersOnDemand: true,