4

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.