3

In this simple vuejs application, I use axios-mock-adapter to mock all the axios request from my application.

All the mock is in the javascript module tests/mock/api.js. In order to use them, I will have to import them in main.js

import "../tests/mock/api";

It works well in Dev mode (npm run serve). However, I don't want this import in Production mode (npm run build). Is there a way to tell webpack ignore this line of import in main.js when we make npm run build?

Hiep
  • 2,483
  • 1
  • 25
  • 32

1 Answers1

4

This should work

if(process.env.NODE_ENV === 'development') require("../tests/mock/api");

See more in How can I conditionally import an ES6 module?

Jacob Goh
  • 19,800
  • 5
  • 53
  • 73