[英]How can I exclude a static file from a Vue CLI build?
My Vue CLI project relies on JSON data from the backend.我的 Vue CLI 项目依赖于后端的 JSON 数据。 Because of CORS issues I copied that file into the project's public
folder which works during development.由于 CORS 问题,我将该文件复制到项目的public
文件夹中,该文件夹在开发过程中有效。 But for the deployment builds I'd like to get rid of that file.但是对于部署版本,我想删除该文件。
How can I exclude that file from the build process?如何从构建过程中排除该文件? I suppose the chainWebpack
method in vue.config.js is the key but I can't find how to tweak the different outputs for serve
and build
.我想chainWebpack
中的chainWebpack
方法是关键,但我找不到如何调整serve
和build
的不同输出。
I got this to work:我得到了这个工作:
module.exports = {
chainWebpack: config => {
if (process.env.NODE_ENV === "production") {
config.plugin("copy").tap(opts => {
opts[0][0].ignore.push({ glob: "someFile.json" });
return opts;
});
}
}
};
The process.env.NODE_ENV === "production"
makes the exclusion only apply to the build
output. process.env.NODE_ENV === "production"
使排除仅适用于build
输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.