fix(build): fix environment variable configuration file failure
This commit is contained in:
parent
e6db0d39b9
commit
bd7b53f14a
|
|
@ -1,3 +1,5 @@
|
||||||
|
VITE_PORT = 3100
|
||||||
|
|
||||||
# Whether to open mock
|
# Whether to open mock
|
||||||
VITE_USE_MOCK = true
|
VITE_USE_MOCK = true
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ VITE_PUBLIC_PATH = ./
|
||||||
VITE_DROP_CONSOLE = true
|
VITE_DROP_CONSOLE = true
|
||||||
|
|
||||||
# Whether to output gz file for packaging
|
# Whether to output gz file for packaging
|
||||||
VITE_BUILD_GZIP = false
|
VITE_BUILD_GZIP = true
|
||||||
|
|
||||||
# Basic interface address SPA
|
# Basic interface address SPA
|
||||||
VITE_GLOB_API_URL=/api
|
VITE_GLOB_API_URL=/api
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,10 @@
|
||||||
- 新增 `v-ripple`水波纹指令
|
- 新增 `v-ripple`水波纹指令
|
||||||
- 新增左侧菜单混合模式
|
- 新增左侧菜单混合模式
|
||||||
|
|
||||||
### ✨ Refactor
|
|
||||||
|
|
||||||
- 移除折叠显示菜单名配置
|
|
||||||
|
|
||||||
### 🐛 Bug Fixes
|
### 🐛 Bug Fixes
|
||||||
|
|
||||||
- 修复混合模式下滚动条丢失问题
|
- 修复混合模式下滚动条丢失问题
|
||||||
|
- 修复环境变量配置失效以及 history 模式下 logo 地址问题
|
||||||
|
|
||||||
## 2.0.0-rc.14 (2020-12-15)
|
## 2.0.0-rc.14 (2020-12-15)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
import { GLOB_CONFIG_FILE_NAME } from '../constant';
|
import { GLOB_CONFIG_FILE_NAME } from '../constant';
|
||||||
import fs, { writeFileSync } from 'fs-extra';
|
import fs, { writeFileSync } from 'fs-extra';
|
||||||
|
|
||||||
import viteConfig from '../../vite.config';
|
|
||||||
import { errorConsole, successConsole, getCwdPath, getEnvConfig } from '../utils';
|
import { errorConsole, successConsole, getCwdPath, getEnvConfig } from '../utils';
|
||||||
import { getShortName } from '../getShortName';
|
import { getShortName } from '../getShortName';
|
||||||
|
|
||||||
|
|
@ -17,7 +16,7 @@ function createConfig(
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const windowConf = `window.${configName}`;
|
const windowConf = `window.${configName}`;
|
||||||
const outDir = viteConfig.outDir || 'dist';
|
const outDir = 'dist';
|
||||||
// Ensure that the variable will not be modified
|
// Ensure that the variable will not be modified
|
||||||
const configStr = `${windowConf}=${JSON.stringify(config)};
|
const configStr = `${windowConf}=${JSON.stringify(config)};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,20 @@
|
||||||
// #!/usr/bin/env node
|
// #!/usr/bin/env node
|
||||||
|
|
||||||
import { sh } from 'tasksfile';
|
|
||||||
|
|
||||||
import { argv } from 'yargs';
|
import { argv } from 'yargs';
|
||||||
import { runBuildConfig } from './buildConf';
|
import { runBuildConfig } from './buildConf';
|
||||||
// import { runUpdateHtml } from './updateHtml';
|
|
||||||
import { errorConsole, successConsole } from '../utils';
|
import { errorConsole, successConsole } from '../utils';
|
||||||
import { startGzipStyle } from '../vite/plugin/gzip/compress';
|
import { startGzipStyle } from '../vite/plugin/gzip/compress';
|
||||||
|
|
||||||
export const runBuild = async (preview = false) => {
|
export const runBuild = async () => {
|
||||||
try {
|
try {
|
||||||
const argvList = argv._;
|
const argvList = argv._;
|
||||||
if (preview) {
|
|
||||||
let cmd = `cross-env NODE_ENV=production vite build`;
|
|
||||||
await sh(cmd, {
|
|
||||||
async: true,
|
|
||||||
nopipe: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate configuration file
|
// Generate configuration file
|
||||||
if (!argvList.includes('no-conf')) {
|
if (!argvList.includes('no-conf')) {
|
||||||
await runBuildConfig();
|
await runBuildConfig();
|
||||||
}
|
}
|
||||||
// await runUpdateHtml();
|
// await runUpdateHtml();
|
||||||
if (!preview) {
|
|
||||||
await startGzipStyle();
|
await startGzipStyle();
|
||||||
}
|
|
||||||
successConsole('Vite Build successfully!');
|
successConsole('Vite Build successfully!');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorConsole('Vite Build Error\n' + error);
|
errorConsole('Vite Build Error\n' + error);
|
||||||
|
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
// Do you need to update the dependencies to prevent package.json from updating the dependencies, and no install after others get the code
|
|
||||||
|
|
||||||
import path from 'path';
|
|
||||||
import fs from 'fs-extra';
|
|
||||||
import { isEqual } from 'lodash';
|
|
||||||
import { sh } from 'tasksfile';
|
|
||||||
import { successConsole, errorConsole } from '../utils';
|
|
||||||
|
|
||||||
const resolve = (dir: string) => {
|
|
||||||
return path.resolve(process.cwd(), dir);
|
|
||||||
};
|
|
||||||
|
|
||||||
const reg = /[\u4E00-\u9FA5\uF900-\uFA2D]/;
|
|
||||||
|
|
||||||
let NEED_INSTALL = false;
|
|
||||||
|
|
||||||
export async function runPreserve() {
|
|
||||||
// rc.6 fixed
|
|
||||||
const cwdPath = process.cwd();
|
|
||||||
if (reg.test(cwdPath)) {
|
|
||||||
errorConsole(
|
|
||||||
'Do not include Chinese, Japanese or Korean in the full path of the project directory, please modify the directory name and run again!'
|
|
||||||
);
|
|
||||||
errorConsole('项目目录全路径请勿包含中文、日文、韩文,请修改目录名后再次重新运行!');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
await fs.mkdirp(resolve('build/.cache'));
|
|
||||||
function checkPkgUpdate() {
|
|
||||||
const pkg = require('../../package.json');
|
|
||||||
const { dependencies, devDependencies } = pkg;
|
|
||||||
const depsFile = resolve('build/.cache/deps.json');
|
|
||||||
if (!fs.pathExistsSync(depsFile)) {
|
|
||||||
NEED_INSTALL = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const depsJson = require('../.cache/deps.json');
|
|
||||||
|
|
||||||
if (!isEqual(depsJson, { dependencies, devDependencies })) {
|
|
||||||
NEED_INSTALL = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
checkPkgUpdate();
|
|
||||||
if (NEED_INSTALL) {
|
|
||||||
// no error
|
|
||||||
successConsole(
|
|
||||||
'A dependency change is detected, and the dependency is being installed to ensure that the dependency is consistent! (Tip: The project will be executed for the first time)!'
|
|
||||||
);
|
|
||||||
try {
|
|
||||||
await sh('npm run bootstrap ', {
|
|
||||||
async: true,
|
|
||||||
nopipe: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
successConsole('Dependency installation is successful, start running the project!');
|
|
||||||
|
|
||||||
const pkg = require('../../package.json');
|
|
||||||
const { dependencies, devDependencies } = pkg;
|
|
||||||
const depsFile = resolve('build/.cache/deps.json');
|
|
||||||
const deps = { dependencies, devDependencies };
|
|
||||||
if (!fs.pathExistsSync(depsFile)) {
|
|
||||||
fs.writeFileSync(depsFile, JSON.stringify(deps));
|
|
||||||
} else {
|
|
||||||
const depsFile = resolve('build/.cache/deps.json');
|
|
||||||
const depsJson = require('../.cache/deps.json');
|
|
||||||
if (!isEqual(depsJson, deps)) {
|
|
||||||
fs.writeFileSync(depsFile, JSON.stringify(deps));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
runPreserve();
|
|
||||||
|
|
@ -4,12 +4,7 @@ import Koa from 'koa';
|
||||||
import staticServer from 'koa-static';
|
import staticServer from 'koa-static';
|
||||||
import portfinder from 'portfinder';
|
import portfinder from 'portfinder';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import viteConfig from '../../vite.config';
|
|
||||||
import { getIPAddress } from '../utils';
|
import { getIPAddress } from '../utils';
|
||||||
// import { runBuild } from './postBuild';
|
|
||||||
|
|
||||||
// const BUILD = 1;
|
|
||||||
// const NO_BUILD = 2;
|
|
||||||
|
|
||||||
// start server
|
// start server
|
||||||
const startApp = () => {
|
const startApp = () => {
|
||||||
|
|
@ -17,7 +12,7 @@ const startApp = () => {
|
||||||
portfinder.basePort = port;
|
portfinder.basePort = port;
|
||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(staticServer(resolve(process.cwd(), viteConfig.outDir || 'dist')));
|
app.use(staticServer(resolve(process.cwd(), 'dist')));
|
||||||
|
|
||||||
portfinder.getPort(async (err, port) => {
|
portfinder.getPort(async (err, port) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
@ -35,25 +30,4 @@ const startApp = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// export const runPreview = async () => {
|
|
||||||
// // const prompt = inquirer.prompt({
|
|
||||||
// // type: 'list',
|
|
||||||
// // message: 'Please select a preview method',
|
|
||||||
// // name: 'type',
|
|
||||||
// // choices: [
|
|
||||||
// // {
|
|
||||||
// // name: 'Preview after packaging',
|
|
||||||
// // value: BUILD,
|
|
||||||
// // },
|
|
||||||
// // {
|
|
||||||
// // name: `No packaging, preview directly (need to have dist file after packaging)`,
|
|
||||||
// // value: NO_BUILD,
|
|
||||||
// // },
|
|
||||||
// // ],
|
|
||||||
// // });
|
|
||||||
// const { type } = await prompt;
|
|
||||||
// if (type === BUILD) {
|
|
||||||
// await runBuild(true);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
startApp();
|
startApp();
|
||||||
|
|
|
||||||
|
|
@ -63,12 +63,12 @@ export function getIPAddress() {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isDevFn(): boolean {
|
export function isDevFn(mode: 'development' | 'production'): boolean {
|
||||||
return process.env.NODE_ENV === 'development';
|
return mode === 'development';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isProdFn(): boolean {
|
export function isProdFn(mode: 'development' | 'production'): boolean {
|
||||||
return process.env.NODE_ENV === 'production';
|
return mode === 'production';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -106,18 +106,11 @@ export interface ViteEnv {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read all environment variable configuration files to process.env
|
// Read all environment variable configuration files to process.env
|
||||||
export function loadEnv(): ViteEnv {
|
export function wrapperEnv(envConf: any): ViteEnv {
|
||||||
const env = process.env.NODE_ENV;
|
|
||||||
const ret: any = {};
|
const ret: any = {};
|
||||||
const envList = [`.env.${env}.local`, `.env.${env}`, '.env.local', '.env', ,];
|
|
||||||
envList.forEach((e) => {
|
|
||||||
dotenv.config({
|
|
||||||
path: e,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const envName of Object.keys(process.env)) {
|
for (const envName of Object.keys(envConf)) {
|
||||||
let realName = (process.env as any)[envName].replace(/\\n/g, '\n');
|
let realName = envConf[envName].replace(/\\n/g, '\n');
|
||||||
realName = realName === 'true' ? true : realName === 'false' ? false : realName;
|
realName = realName === 'true' ? true : realName === 'false' ? false : realName;
|
||||||
if (envName === 'VITE_PORT') {
|
if (envName === 'VITE_PORT') {
|
||||||
realName = Number(realName);
|
realName = Number(realName);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { gzip } from 'zlib';
|
import { gzip } from 'zlib';
|
||||||
import { readFileSync, writeFileSync } from 'fs';
|
import { readFileSync, writeFileSync } from 'fs';
|
||||||
import { GzipPluginOptions } from './types';
|
import { GzipPluginOptions } from './types';
|
||||||
import viteConfig from '../../../../vite.config';
|
|
||||||
import { readAllFile, getCwdPath, isBuildGzip, isSiteMode } from '../../../utils';
|
import { readAllFile, getCwdPath, isBuildGzip, isSiteMode } from '../../../utils';
|
||||||
|
|
||||||
export function startGzip(
|
export function startGzip(
|
||||||
|
|
@ -22,8 +21,8 @@ export function startGzip(
|
||||||
// 手动压缩css
|
// 手动压缩css
|
||||||
export async function startGzipStyle() {
|
export async function startGzipStyle() {
|
||||||
if (isBuildGzip() || isSiteMode()) {
|
if (isBuildGzip() || isSiteMode()) {
|
||||||
const outDir = viteConfig.outDir || 'dist';
|
const outDir = 'dist';
|
||||||
const assets = viteConfig.assetsDir || '_assets';
|
const assets = '_assets';
|
||||||
const allCssFile = readAllFile(getCwdPath(outDir, assets), /\.(css)$/);
|
const allCssFile = readAllFile(getCwdPath(outDir, assets), /\.(css)$/);
|
||||||
for (const path of allCssFile) {
|
for (const path of allCssFile) {
|
||||||
const source = readFileSync(path);
|
const source = readFileSync(path);
|
||||||
|
|
|
||||||
|
|
@ -7,16 +7,21 @@ import { hmScript } from '../hm';
|
||||||
import pkg from '../../../package.json';
|
import pkg from '../../../package.json';
|
||||||
import { GLOB_CONFIG_FILE_NAME } from '../../constant';
|
import { GLOB_CONFIG_FILE_NAME } from '../../constant';
|
||||||
|
|
||||||
export function setupHtmlPlugin(plugins: Plugin[], env: ViteEnv) {
|
export function setupHtmlPlugin(
|
||||||
|
plugins: Plugin[],
|
||||||
|
env: ViteEnv,
|
||||||
|
mode: 'development' | 'production'
|
||||||
|
) {
|
||||||
const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env;
|
const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env;
|
||||||
|
|
||||||
const htmlPlugin = ViteHtmlPlugin({
|
const htmlPlugin = ViteHtmlPlugin({
|
||||||
// html title
|
// html title
|
||||||
title: VITE_GLOB_APP_TITLE,
|
title: VITE_GLOB_APP_TITLE,
|
||||||
minify: isProdFn(),
|
minify: isProdFn(mode),
|
||||||
options: {
|
options: {
|
||||||
|
publicPath: VITE_PUBLIC_PATH,
|
||||||
// Package and insert additional configuration files
|
// Package and insert additional configuration files
|
||||||
injectConfig: isProdFn()
|
injectConfig: isProdFn(mode)
|
||||||
? `<script src='${VITE_PUBLIC_PATH || './'}${GLOB_CONFIG_FILE_NAME}?v=${
|
? `<script src='${VITE_PUBLIC_PATH || './'}${GLOB_CONFIG_FILE_NAME}?v=${
|
||||||
pkg.version
|
pkg.version
|
||||||
}-${new Date().getTime()}'></script>`
|
}-${new Date().getTime()}'></script>`
|
||||||
|
|
|
||||||
|
|
@ -8,21 +8,21 @@ import gzipPlugin from './gzip/index';
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import pkg from '../../../package.json';
|
import pkg from '../../../package.json';
|
||||||
import { isProdFn, isSiteMode, ViteEnv, isReportMode, isBuildGzip } from '../../utils';
|
import { isSiteMode, ViteEnv, isReportMode, isBuildGzip } from '../../utils';
|
||||||
import { setupHtmlPlugin } from './html';
|
import { setupHtmlPlugin } from './html';
|
||||||
import { setupPwaPlugin } from './pwa';
|
import { setupPwaPlugin } from './pwa';
|
||||||
import { setupMockPlugin } from './mock';
|
import { setupMockPlugin } from './mock';
|
||||||
|
|
||||||
// gen vite plugins
|
// gen vite plugins
|
||||||
export function createVitePlugins(viteEnv: ViteEnv) {
|
export function createVitePlugins(viteEnv: ViteEnv, mode: 'development' | 'production') {
|
||||||
const vitePlugins: VitePlugin[] = [];
|
const vitePlugins: VitePlugin[] = [];
|
||||||
|
|
||||||
// vite-plugin-html
|
// vite-plugin-html
|
||||||
setupHtmlPlugin(vitePlugins, viteEnv);
|
setupHtmlPlugin(vitePlugins, viteEnv, mode);
|
||||||
// vite-plugin-pwa
|
// vite-plugin-pwa
|
||||||
setupPwaPlugin(vitePlugins, viteEnv);
|
setupPwaPlugin(vitePlugins, viteEnv, mode);
|
||||||
// vite-plugin-mock
|
// vite-plugin-mock
|
||||||
setupMockPlugin(vitePlugins, viteEnv);
|
setupMockPlugin(vitePlugins, viteEnv, mode);
|
||||||
|
|
||||||
// vite-plugin-purge-icons
|
// vite-plugin-purge-icons
|
||||||
vitePlugins.push(PurgeIcons());
|
vitePlugins.push(PurgeIcons());
|
||||||
|
|
@ -34,12 +34,11 @@ export function createVitePlugins(viteEnv: ViteEnv) {
|
||||||
export function createRollupPlugin() {
|
export function createRollupPlugin() {
|
||||||
const rollupPlugins: rollupPlugin[] = [];
|
const rollupPlugins: rollupPlugin[] = [];
|
||||||
|
|
||||||
if (!isProdFn() && isReportMode()) {
|
if (isReportMode()) {
|
||||||
// rollup-plugin-visualizer
|
// rollup-plugin-visualizer
|
||||||
rollupPlugins.push(visualizer({ filename: './build/.cache/stats.html', open: true }) as Plugin);
|
rollupPlugins.push(visualizer({ filename: './build/.cache/stats.html', open: true }) as Plugin);
|
||||||
}
|
}
|
||||||
|
if (isBuildGzip() || isSiteMode()) {
|
||||||
if (!isProdFn() && (isBuildGzip() || isSiteMode())) {
|
|
||||||
// rollup-plugin-gizp
|
// rollup-plugin-gizp
|
||||||
rollupPlugins.push(gzipPlugin());
|
rollupPlugins.push(gzipPlugin());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,22 @@ import { createMockServer } from 'vite-plugin-mock';
|
||||||
import type { Plugin } from 'vite';
|
import type { Plugin } from 'vite';
|
||||||
import { isDevFn, ViteEnv } from '../../utils';
|
import { isDevFn, ViteEnv } from '../../utils';
|
||||||
|
|
||||||
export function setupMockPlugin(plugins: Plugin[], env: ViteEnv) {
|
export function setupMockPlugin(
|
||||||
|
plugins: Plugin[],
|
||||||
|
env: ViteEnv,
|
||||||
|
mode: 'development' | 'production'
|
||||||
|
) {
|
||||||
const { VITE_USE_MOCK } = env;
|
const { VITE_USE_MOCK } = env;
|
||||||
|
|
||||||
|
const useMock = isDevFn(mode) && VITE_USE_MOCK;
|
||||||
|
|
||||||
|
if (useMock) {
|
||||||
const mockPlugin = createMockServer({
|
const mockPlugin = createMockServer({
|
||||||
ignore: /^\_/,
|
ignore: /^\_/,
|
||||||
mockPath: 'mock',
|
mockPath: 'mock',
|
||||||
showTime: true,
|
showTime: true,
|
||||||
|
localEnabled: useMock,
|
||||||
});
|
});
|
||||||
if (isDevFn() && VITE_USE_MOCK) {
|
|
||||||
plugins.push(mockPlugin);
|
plugins.push(mockPlugin);
|
||||||
}
|
}
|
||||||
return plugins;
|
return plugins;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,13 @@
|
||||||
import { VitePWA } from 'vite-plugin-pwa';
|
import { VitePWA } from 'vite-plugin-pwa';
|
||||||
import type { Plugin } from 'vite';
|
import type { Plugin } from 'vite';
|
||||||
import { isProdFn, ViteEnv } from '../../utils';
|
import { ViteEnv } from '../../utils';
|
||||||
|
|
||||||
export function setupPwaPlugin(plugins: Plugin[], env: ViteEnv) {
|
export function setupPwaPlugin(
|
||||||
|
plugins: Plugin[],
|
||||||
|
env: ViteEnv,
|
||||||
|
// @ts-ignore
|
||||||
|
mode: 'development' | 'production'
|
||||||
|
) {
|
||||||
const { VITE_USE_PWA } = env;
|
const { VITE_USE_PWA } = env;
|
||||||
|
|
||||||
const pwaPlugin = VitePWA({
|
const pwaPlugin = VitePWA({
|
||||||
|
|
@ -23,8 +28,7 @@ export function setupPwaPlugin(plugins: Plugin[], env: ViteEnv) {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
if (VITE_USE_PWA) {
|
||||||
if (isProdFn() && VITE_USE_PWA) {
|
|
||||||
plugins.push(pwaPlugin);
|
plugins.push(pwaPlugin);
|
||||||
}
|
}
|
||||||
return plugins;
|
return plugins;
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,31 @@ type ProxyItem = [string, string];
|
||||||
|
|
||||||
type ProxyList = ProxyItem[];
|
type ProxyList = ProxyItem[];
|
||||||
|
|
||||||
const reg = /^https:\/\//;
|
type ProxyTargetList = Record<
|
||||||
|
string,
|
||||||
|
{
|
||||||
|
target: string;
|
||||||
|
changeOrigin: boolean;
|
||||||
|
rewrite: (path: string) => any;
|
||||||
|
secure?: boolean;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
|
||||||
|
const httpsRE = /^https:\/\//;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate proxy
|
* Generate proxy
|
||||||
* @param list
|
* @param list
|
||||||
*/
|
*/
|
||||||
export function createProxy(list: ProxyList = []) {
|
export function createProxy(list: ProxyList = []) {
|
||||||
const ret: any = {};
|
const ret: ProxyTargetList = {};
|
||||||
for (const [prefix, target] of list) {
|
for (const [prefix, target] of list) {
|
||||||
const isHttps = reg.test(target);
|
const isHttps = httpsRE.test(target);
|
||||||
|
|
||||||
ret[prefix] = {
|
ret[prefix] = {
|
||||||
target: target,
|
target: target,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path: string) => path.replace(new RegExp(`^${prefix}`), ''),
|
rewrite: (path) => path.replace(new RegExp(`^${prefix}`), ''),
|
||||||
// https is require secure=false
|
// https is require secure=false
|
||||||
...(isHttps ? { secure: false } : {}),
|
...(isHttps ? { secure: false } : {}),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,11 @@
|
||||||
</style>
|
</style>
|
||||||
<div class="app-loading">
|
<div class="app-loading">
|
||||||
<div class="app-loading-wrap">
|
<div class="app-loading-wrap">
|
||||||
<img src="./resource/img/logo.png" class="app-loading-logo" alt="Logo" />
|
<img
|
||||||
|
src="<%= viteHtmlPluginOptions.publicPath %>resource/img/logo.png"
|
||||||
|
class="app-loading-logo"
|
||||||
|
alt="Logo"
|
||||||
|
/>
|
||||||
<div class="app-loading-dots">
|
<div class="app-loading-dots">
|
||||||
<span class="dot dot-spin"><i></i><i></i><i></i><i></i></span>
|
<span class="dot dot-spin"><i></i><i></i><i></i><i></i></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
"version": "2.0.0-rc.14",
|
"version": "2.0.0-rc.14",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"bootstrap": "yarn install",
|
"bootstrap": "yarn install",
|
||||||
"serve": "esno ./build/script/preserve.ts && cross-env NODE_ENV=development vite",
|
"serve": "cross-env vite --mode=development",
|
||||||
"build": "cross-env NODE_ENV=production vite build && esno ./build/script/postBuild.ts",
|
"build": "cross-env vite build --mode=production && esno ./build/script/postBuild.ts",
|
||||||
"build:site": "cross-env SITE=true npm run build ",
|
"build:site": "cross-env SITE=true npm run build ",
|
||||||
"build:no-cache": "yarn clean:cache && npm run build",
|
"build:no-cache": "yarn clean:cache && npm run build",
|
||||||
"typecheck": "typecheck .",
|
"typecheck": "typecheck .",
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ setupErrorHandle(app);
|
||||||
|
|
||||||
// Mount when the route is ready
|
// Mount when the route is ready
|
||||||
router.isReady().then(() => {
|
router.isReady().then(() => {
|
||||||
app.mount('#app');
|
app.mount('#app', true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// The development environment takes effect
|
// The development environment takes effect
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,9 @@ import { basicRoutes } from './routes/';
|
||||||
import { scrollBehavior } from './scrollBehavior';
|
import { scrollBehavior } from './scrollBehavior';
|
||||||
import { REDIRECT_NAME } from './constant';
|
import { REDIRECT_NAME } from './constant';
|
||||||
|
|
||||||
export const hashRouter = createWebHashHistory();
|
|
||||||
|
|
||||||
// app router
|
// app router
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: hashRouter,
|
history: createWebHashHistory(),
|
||||||
routes: basicRoutes as RouteRecordRaw[],
|
routes: basicRoutes as RouteRecordRaw[],
|
||||||
strict: true,
|
strict: true,
|
||||||
scrollBehavior: scrollBehavior,
|
scrollBehavior: scrollBehavior,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import type { UserConfig, Resolver } from 'vite';
|
import type { UserConfig, Resolver } from 'vite';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
|
|
||||||
|
import { loadEnv } from 'vite';
|
||||||
|
|
||||||
import { modifyVars } from './build/config/lessModifyVars';
|
import { modifyVars } from './build/config/lessModifyVars';
|
||||||
import { createProxy } from './build/vite/proxy';
|
import { createProxy } from './build/vite/proxy';
|
||||||
import { configManualChunk } from './build/vite/optimizer';
|
import { configManualChunk } from './build/vite/optimizer';
|
||||||
|
|
@ -8,16 +10,12 @@ import { configManualChunk } from './build/vite/optimizer';
|
||||||
import globbyTransform from './build/vite/plugin/transform/globby';
|
import globbyTransform from './build/vite/plugin/transform/globby';
|
||||||
import dynamicImportTransform from './build/vite/plugin/transform/dynamic-import';
|
import dynamicImportTransform from './build/vite/plugin/transform/dynamic-import';
|
||||||
|
|
||||||
import { loadEnv } from './build/utils';
|
import { wrapperEnv } from './build/utils';
|
||||||
|
|
||||||
import { createRollupPlugin, createVitePlugins } from './build/vite/plugin';
|
import { createRollupPlugin, createVitePlugins } from './build/vite/plugin';
|
||||||
|
|
||||||
const pkg = require('./package.json');
|
const pkg = require('./package.json');
|
||||||
|
|
||||||
const viteEnv = loadEnv();
|
|
||||||
|
|
||||||
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE, VITE_DYNAMIC_IMPORT } = viteEnv;
|
|
||||||
|
|
||||||
function pathResolve(dir: string) {
|
function pathResolve(dir: string) {
|
||||||
return resolve(__dirname, '.', dir);
|
return resolve(__dirname, '.', dir);
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +28,17 @@ const root: string = process.cwd();
|
||||||
|
|
||||||
const resolvers: Resolver[] = [];
|
const resolvers: Resolver[] = [];
|
||||||
|
|
||||||
const viteConfig: UserConfig = {
|
export default (mode: 'development' | 'production'): UserConfig => {
|
||||||
|
const env = loadEnv(mode, root);
|
||||||
|
const viteEnv = wrapperEnv(env);
|
||||||
|
const {
|
||||||
|
VITE_PORT,
|
||||||
|
VITE_PUBLIC_PATH,
|
||||||
|
VITE_PROXY,
|
||||||
|
VITE_DROP_CONSOLE,
|
||||||
|
VITE_DYNAMIC_IMPORT,
|
||||||
|
} = viteEnv;
|
||||||
|
return {
|
||||||
root,
|
root,
|
||||||
alias,
|
alias,
|
||||||
/**
|
/**
|
||||||
|
|
@ -98,7 +106,7 @@ const viteConfig: UserConfig = {
|
||||||
|
|
||||||
proxy: createProxy(VITE_PROXY),
|
proxy: createProxy(VITE_PROXY),
|
||||||
|
|
||||||
plugins: createVitePlugins(viteEnv),
|
plugins: createVitePlugins(viteEnv, mode),
|
||||||
|
|
||||||
rollupInputOptions: {
|
rollupInputOptions: {
|
||||||
plugins: createRollupPlugin(),
|
plugins: createRollupPlugin(),
|
||||||
|
|
@ -109,5 +117,4 @@ const viteConfig: UserConfig = {
|
||||||
manualChunks: configManualChunk,
|
manualChunks: configManualChunk,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
};
|
||||||
export default viteConfig;
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue