This commit is contained in:
eric
2026-03-07 20:02:47 -06:00
parent 20fe6ca205
commit aed78201a9
8 changed files with 1213 additions and 1234 deletions

View File

@@ -6,5 +6,15 @@ module.exports = {
'process.env.TARO_API_API': JSON.stringify("/api")
},
mini: {},
h5: {}
h5: {
devServer: {
hot: true,
client: {
overlay: {
errors: true,
warnings: false
}
}
}
}
}

View File

@@ -1,5 +1,6 @@
import path from "path";
const WebpackObfuscator = require("webpack-obfuscator");
const isDev = process.env.NODE_ENV === "development";
const config = {
projectName: "cityh5",
@@ -15,25 +16,28 @@ const config = {
compiler: "webpack5",
cache: {
enable: true, // ✅ 开启缓存,加快构建
enable: true,
type: "filesystem",
},
h5: {
webpackChain(chain) {
// ✅ 避免 undefined.js,统一使用标准占位符
chain.output.filename("static/js/[name].[contenthash:8].js");
chain.output.chunkFilename("static/js/[name].[contenthash:8].js");
if (isDev) {
chain.output.filename("static/js/[name].js");
chain.output.chunkFilename("static/js/[name].js");
chain.devtool("eval-cheap-module-source-map");
} else {
chain.output.filename("static/js/[name].[contenthash:8].js");
chain.output.chunkFilename("static/js/[name].[contenthash:8].js");
chain.plugin("MiniCssExtractPlugin").use(require("mini-css-extract-plugin"), [
{
filename: "static/css/[name].[contenthash:8].css",
chunkFilename: "static/css/[name].[contenthash:8].css",
},
]);
chain.plugin("MiniCssExtractPlugin").use(require("mini-css-extract-plugin"), [
{
filename: "static/css/[name].[contenthash:8].css",
chunkFilename: "static/css/[name].[contenthash:8].css",
},
]);
if (process.env.NODE_ENV === "production") {
// ✅ 保留原有混淆逻辑
const WebpackObfuscator = require("webpack-obfuscator");
chain.plugin("obfuscator").use(WebpackObfuscator, [
{
rotateStringArray: true,
@@ -53,7 +57,6 @@ const config = {
]);
}
// ✅ markdown 支持
chain.module
.rule("markdown")
.test(/\.md$/)
@@ -61,7 +64,6 @@ const config = {
.loader("raw-loader")
.end();
// ✅ ico 支持
chain.module
.rule("ico")
.test(/\.ico$/)
@@ -71,7 +73,7 @@ const config = {
},
esnextModules: ["taro-ui"],
publicPath: "/", // ✅ 部署到根目录;如果是子路径,需要改成 /xxx/
publicPath: "/",
staticDirectory: "static",
postcss: {
@@ -94,6 +96,7 @@ const config = {
},
devServer: {
hot: true,
proxy: {
"/api/": {
target: "http://localhost:8700",
@@ -101,7 +104,7 @@ const config = {
changeOrigin: true,
},
},
allowedHosts: ["nomadro.com", "localhost", ".nomadro.com", "hackrobot.cn",".ngrok-free.app"],
allowedHosts: ["nomadro.com", "localhost", ".nomadro.com", "hackrobot.cn", ".ngrok-free.app"],
},
htmlPluginOption: {