React版本:?"react": "^18.2.0"
1、在package.json平級目錄下創建'.env'文件
2、在‘.env’文件里配置環境變量
【1】PUBLIC_URL
描述:編譯時文件的base-href
官方描述:
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
// "public path" at which the app is served.
// webpack needs to know it to put the right <script> hrefs into HTML even in
// single-page apps that may serve index.html for nested URLs like /todos/42.
// We can't use a relative path in HTML because we don't want to load something
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
const publicUrlOrPath = getPublicUrlOrPath(process.env.NODE_ENV === 'development',require(resolveApp('package.json')).homepage,process.env.PUBLIC_URL
);
配置方式:
PUBLIC_URL = '/zyk'
效果:
編譯后的文件都增加了‘/zyk’前綴
?
【2】BUILD_PATH
描述:編譯后文件夾名稱,默認是‘build’
配置方式:
BUILD_PATH = 'dist'
效果:
?