Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

设置envDir参数,热更新失效。 #16649

Closed
7 tasks done
Aigui opened this issue May 10, 2024 · 1 comment
Closed
7 tasks done

设置envDir参数,热更新失效。 #16649

Aigui opened this issue May 10, 2024 · 1 comment

Comments

@Aigui
Copy link

Aigui commented May 10, 2024

Describe the bug

像这样设置envDir: "./src/project/electronicCalendar",环境变量可以读取到但是热更新失效,
vite版本是5.0.0。

Reproduction

wu

Steps to reproduce

No response

System Info

windows 10

Used Package Manager

npm

Logs

export default ({ mode }) => {
const env = loadEnv(mode, ${process.cwd()});
return defineConfig({
envDir: "./src/project/electronicCalendar",
base: env.VITE_BASE_URL,
esbuild: {
// 避免iconfont打包后乱码
charset: "ascii"
},
plugins: [
vue(),
createHtmlPlugin({
entry: "/src/project/electronicCalendar/main.js"
}),
// Icons图标自动下载
Icons({ autoInstall: true }),
AutoImport({
resolvers: [
// 这个是组件自动导入
ElementPlusResolver(),
IconsResolver({
prefix: "icon"
})
]
}),
// 自动导入components下的自定义组件
Components({
// 可以让我们使用自己定义组件的时候免去 import 的麻烦
dirs: ["src/components/", "src/layouts/components/", "src/project/electronicCalendar/components/"],
// 配置需要将哪些后缀类型的文件进行自动按需引入,'vue'为默认值
extensions: ["vue"],
// 解析组件
resolvers: [
// 这个是组件自动导入
ElementPlusResolver(),
// 自动注册图标组件
IconsResolver({
// 修改Icon组件前缀,不设置则默认为i,禁用则设置为false
prefix: "icon",
// 指定collection,即指定为elementplus图标集ep
enabledCollections: ["ep"]
})
]
}),
legacyPlugin({
targets: ["chrome 52"] // 需要兼容的目标列表,可以设置多个
}),
viteCompression({
filter: /.(js|mjs|json|css|html)$/i, //过滤器,对哪些类型的文件进行压缩,默认为/.(js|mjs|json|css|html)$/i
verbose: true, //是否在控制台输出压缩结果,默认为 true
disable: false, //是否禁用压缩,默认为 false
threshold: 10240, //启用压缩的文件大小限制,单位是字节,默认为 0
deleteOriginFile: false, //压缩后是否删除原文件,默认为 false
algorithm: "gzip", //采用的压缩算法,默认是 gzip
ext: ".gz" //生成的压缩包后缀
})
],
resolve: {
alias: {
"@submodule": fileURLToPath(new URL("./", import.meta.url)),
"@": ${process.cwd()}/src
},
/* 暂时先加.vue, .js, .json */
extensions: [".vue", ".js", ".json"]
},
build: {
minify: "terser",
outDir: "../production/electronicCalendar",
terserOptions: {
compress: {
//移除console和debugger
drop_console: true,
drop_debugger: true
}
},
// 关闭文件计算
reportCompressedSize: false,
// 关闭生成map文件 可以达到缩小打包体积
sourcemap: false, // 这个生产环境一定要关闭,不然打包的产物会很大
rollupOptions: {
output: {
//静态资源分类打包
chunkFileNames: "static/js/[name]-[hash].js",
entryFileNames: "static/js/[name]-[hash].js",
assetFileNames: "static/[ext]/[name]-[hash].[ext]",
manualChunks(id) {
//静态资源分拆打包
if (id.includes("node_modules")) {
return id.toString().split("node_modules/")[1].split("/")[0].toString();
}
}
}
}
}
});
};

Validations

Copy link

Hello @Aigui. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants