简体   繁体   English

如何从 Vue CLI 构建中排除静态文件?

[英]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方法是关键,但我找不到如何调整servebuild的不同输出。

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.

相关问题 在 Vue CLI 3 中运行 build:electron 后,如何将静态 config.json 文件中的值读取到 Vue 文件中的 TypeScript? - How can I read values from a static config.json file to TypeScript in a Vue file after running build:electron in Vue CLI 3? 如何在 vite 中排除 vue 文件夹? - How can I exclude a vue folder from being build in vite? 如何停止在我的chunk-vendors.js文件中包含vue.js.min来停止vue cli3构建? - How can I stop vue cli3 build from including vue.js.min in my chunk-vendors.js file? 如何使用 vue-cli 中的 php 文件? - How can I use php file from vue-cli? 我如何设置npm build选项? 我想将css和js文件放在静态文件夹中。 (vue cli 3,npm,vuetify) - how can i set npm build option? I want to put my css and js file in static folder. (vue cli 3,npm, vuetify) 带有 Vue CLI 的 Vue 2 - 如何制作 src/static static 以便我可以使用其中的图像? - Vue 2 with Vue CLI - How to make src/static static so I can use images that are in there? 如何在 vue-cli 中设置生产构建路径? - How can I set production build path in vue-cli? 如何使用 Webpack (vue-cli) 从生产构建中排除 CommonJS 库 - How to exclude CommonJS libs from production build with Webpack (vue-cli) 如何从构建中排除 vuetify 和 vue? - How to exclude vuetify and vue from the build? Vue 项目(vue-cli 3/4) 当我在 CDN 上托管 static 文件时,延迟加载路由无法到达 static 文件 - Vue project(vue-cli 3/4) lazy loading route can not reach static file when I host static files on CDN
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM