monorepo-microservice-rbac/apps/aorta/scripts/webpack.dev.ts

70 lines
2.6 KiB
TypeScript
Raw Permalink Normal View History

2023-08-27 14:37:59 +08:00
import path from "path";
import { merge } from "webpack-merge";
import webpack, { Configuration as WebpackConfiguration } from "webpack";
import WebpackDevServer from "webpack-dev-server";
import { Configuration as WebpackDevServerConfiguration } from "webpack-dev-server";
import baseConfig from "./webpack.common";
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
const FriendlyErrorsWebpackPlugin = require("friendly-errors-webpack-plugin");
import { proxyMap } from "./dev.proxy";
/**
* tab
* create-react-app
* https://github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/openChrome.applescript
* webpack-dev-server的配置中的自动打开 open: false
*/
2023-10-09 16:16:52 +08:00
// import openBrowser from "./util/openBrowser";
2023-08-27 14:37:59 +08:00
interface Configuration extends WebpackConfiguration {
devServer?: WebpackDevServerConfiguration;
}
2023-12-21 12:49:50 +08:00
const host = "0.0.0.0";
2023-08-27 14:37:59 +08:00
const port = 9000;
// 合并公共配置,并添加开发环境配置
const devConfig: Configuration = merge(baseConfig, {
mode: "development", // 开发模式,打包更加快速,省了代码优化步骤
/**
* eval-cheap-module-source-map
* , eval ,
* ,,, cheap
* ,, module
*/
devtool: "eval-cheap-module-source-map",
stats: "errors-only",
plugins: [
2023-10-09 16:16:52 +08:00
new ReactRefreshWebpackPlugin({ overlay: false }), // 添加热更新插件
2023-08-27 14:37:59 +08:00
new FriendlyErrorsWebpackPlugin(),
],
});
const devServer = new WebpackDevServer(
{
host, // 地址
port, // 端口
open: false, // 是否自动打开,关闭
setupExitSignals: true, // 允许在 SIGINT 和 SIGTERM 信号时关闭开发服务器和退出进程。
compress: false, // gzip压缩,开发环境不开启,提升热更新速度
hot: true, // 开启热更新后面会讲react模块热替换具体配置
historyApiFallback: true, // 解决history路由404问题
static: {
directory: path.join(__dirname, "../public"), // 托管静态资源public文件夹
},
headers: { "Access-Control-Allow-Origin": "*" },
proxy: proxyMap,
2023-10-09 16:16:52 +08:00
client: {
progress: true,
},
2023-08-27 14:37:59 +08:00
},
webpack(devConfig)
);
devServer.start().then(() => {
// 启动界面
2023-10-09 16:16:52 +08:00
// openBrowser(`http://${host}:${port}`);
2023-08-27 14:37:59 +08:00
});
export default devConfig;