How can I exclude a static file from a Vue CLI build?

Viewed 1368

My Vue CLI project relies on JSON data from the backend. Because of CORS issues I copied that file into the project's public folder which works during development. 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.

1 Answers

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.

Related