提交 c1a4600b 作者: vben

feat: vite preview

上级 2eb2d2a0
import chalk from 'chalk';
import Koa from 'koa';
// import inquirer from 'inquirer';
import staticServer from 'koa-static';
import portfinder from 'portfinder';
import { resolve } from 'path';
import { getIPAddress } from '../utils';
// start server
const startApp = () => {
const port = 9680;
portfinder.basePort = port;
const app = new Koa();
app.use(staticServer(resolve(process.cwd(), 'dist')));
portfinder.getPort(async (err, port) => {
if (err) {
throw err;
} else {
app.listen(port, function () {
const empty = ' ';
const common = `The preview program is already running:
- LOCAL: http://localhost:${port}/
- NETWORK: http://${getIPAddress()}:${port}/
`;
console.log(chalk.cyan('\n' + empty + common));
});
}
});
};
startApp();
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import { networkInterfaces } from 'os';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
import chalk from 'chalk'; import chalk from 'chalk';
// import execa from 'execa';
export const isFunction = (arg: unknown): arg is (...args: any[]) => any => export const isFunction = (arg: unknown): arg is (...args: any[]) => any =>
typeof arg === 'function'; typeof arg === 'function';
...@@ -11,25 +9,6 @@ export const isFunction = (arg: unknown): arg is (...args: any[]) => any => ...@@ -11,25 +9,6 @@ export const isFunction = (arg: unknown): arg is (...args: any[]) => any =>
export const isRegExp = (arg: unknown): arg is RegExp => export const isRegExp = (arg: unknown): arg is RegExp =>
Object.prototype.toString.call(arg) === '[object RegExp]'; Object.prototype.toString.call(arg) === '[object RegExp]';
/**
* get client ip address
*/
export function getIPAddress() {
let interfaces = networkInterfaces();
for (let devName in interfaces) {
let iFace = interfaces[devName];
if (!iFace) return;
for (let i = 0; i < iFace.length; i++) {
let alias = iFace[i];
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
return alias.address;
}
}
}
return '';
}
export function isDevFn(mode: string): boolean { export function isDevFn(mode: string): boolean {
return mode === 'development'; return mode === 'development';
} }
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
"build": "cross-env NODE_ENV=production vite build && esno ./build/script/postBuild.ts", "build": "cross-env NODE_ENV=production vite build && esno ./build/script/postBuild.ts",
"build:no-cache": "yarn clean:cache && npm run build", "build:no-cache": "yarn clean:cache && npm run build",
"report": "cross-env REPORT=true npm run build ", "report": "cross-env REPORT=true npm run build ",
"preview": "npm run build && esno ./build/script/preview.ts", "preview": "npm run build && vite preview",
"preview:dist": "esno ./build/script/preview.ts", "preview:dist": "vite preview",
"log": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0", "log": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite", "clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite",
"clean:lib": "npx rimraf node_modules", "clean:lib": "npx rimraf node_modules",
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
"dependencies": { "dependencies": {
"@iconify/iconify": "^2.0.0-rc.6", "@iconify/iconify": "^2.0.0-rc.6",
"@vueuse/core": "^4.0.10", "@vueuse/core": "^4.0.10",
"ant-design-vue": "^2.0.0-rc.9", "ant-design-vue": "2.0.0-rc.8",
"apexcharts": "^3.23.1", "apexcharts": "^3.23.1",
"axios": "^0.21.1", "axios": "^0.21.1",
"crypto-es": "^1.2.6", "crypto-es": "^1.2.6",
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
"@commitlint/config-conventional": "^11.0.0", "@commitlint/config-conventional": "^11.0.0",
"@iconify/json": "^1.1.290", "@iconify/json": "^1.1.290",
"@ls-lint/ls-lint": "^1.9.2", "@ls-lint/ls-lint": "^1.9.2",
"@purge-icons/generated": "^0.5.2", "@purge-icons/generated": "^0.6.0",
"@types/echarts": "^4.9.3", "@types/echarts": "^4.9.3",
"@types/fs-extra": "^9.0.6", "@types/fs-extra": "^9.0.6",
"@types/http-proxy": "^1.17.5", "@types/http-proxy": "^1.17.5",
...@@ -81,11 +81,8 @@ ...@@ -81,11 +81,8 @@
"esno": "^0.4.0", "esno": "^0.4.0",
"fs-extra": "^9.1.0", "fs-extra": "^9.1.0",
"husky": "^4.3.8", "husky": "^4.3.8",
"koa": "^2.13.1",
"koa-static": "^5.0.0",
"less": "^4.1.0", "less": "^4.1.0",
"lint-staged": "^10.5.3", "lint-staged": "^10.5.3",
"portfinder": "^1.0.28",
"postcss": "^8.2.4", "postcss": "^8.2.4",
"postcss-import": "^14.0.0", "postcss-import": "^14.0.0",
"prettier": "^2.2.1", "prettier": "^2.2.1",
...@@ -98,10 +95,10 @@ ...@@ -98,10 +95,10 @@
"stylelint-order": "^4.1.0", "stylelint-order": "^4.1.0",
"ts-node": "^9.1.1", "ts-node": "^9.1.1",
"typescript": "^4.1.3", "typescript": "^4.1.3",
"vite": "2.0.0-beta.44", "vite": "2.0.0-beta.47",
"vite-plugin-html": "^2.0.0-beta.6", "vite-plugin-html": "^2.0.0-beta.6",
"vite-plugin-mock": "^2.0.0-rc.2", "vite-plugin-mock": "^2.0.0-rc.2",
"vite-plugin-purge-icons": "^0.5.2", "vite-plugin-purge-icons": "^0.6.0",
"vite-plugin-pwa": "^0.3.10", "vite-plugin-pwa": "^0.3.10",
"vite-plugin-style-import": "^0.4.6", "vite-plugin-style-import": "^0.4.6",
"vue-eslint-parser": "^7.4.1", "vue-eslint-parser": "^7.4.1",
......
...@@ -49,22 +49,12 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { ...@@ -49,22 +49,12 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
drop_console: VITE_DROP_CONSOLE, drop_console: VITE_DROP_CONSOLE,
}, },
}, },
// minify: 'esbuild',
rollupOptions: { rollupOptions: {
output: { output: {
compact: true, compact: true,
manualChunks: undefined, manualChunks: undefined,
}, },
}, },
minify: 'esbuild',
commonjsOptions: {
ignore: [
// xlsx
'fs',
'crypto',
'stream',
],
},
}, },
define: { define: {
__VERSION__: pkg.version, __VERSION__: pkg.version,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论