24
loading...
This website collects cookies to deliver better user experience
medium.com
. If it's supposed to be served on a sub-path like /apps/my-app
, you have to tell the build script what the exact path it is. The way it receives the path value is through the env variable, actually as PUBLIC_URL
.PUBLIC_URL=/apps/my-app
#!/bin/bash
export PUBLIC_URL=/apps/my-app
/node_modules/.bin/react-scripts build
build-[stack-name].sh
, tell the build manager(like Jenkins) that executes the correct shell script.PATH := ./node_modules/.bin:${PATH}
.PHONY: start build
start:
react-scripts start
build:
export PUBLIC_URL=/apps/my-app; \
react-scripts build
target
by Makefile) defined by the Makefile. In the build target, the first line is to set the PUBLIC_URL. Please be noticed it ends with a semicolon followed by a backslash. This is because each line in a target is executed in a standalone shell by default, which means the env variable set in the first line is not readable by the second line. The sign that a semicolon followed by a backslash asks Makefile that the next line executes in the current shell, which means they share the same context. In this way, the second line receives the env variable.process.env[name] = value
), shell script works more simple and easy. And the great part is, shell script works for all unix like OS, not only Nodejs. In this point of view, it's sort of cross-platform.