How webpack ignores import statements

in my main.js import router from". / router"

now I want to implement the webpack configuration
1. The command line npm run dev does not quote router , which means not writing this line of code
2. Quote router

when you use npm run build on the command line.

and how to ignore the content between certain characters, such as

/****/
import router from "./router"
/****/

the following is my project structure, solve!


import is static and cannot be loaded. It can be replaced with require to determine the environment variables.


answer on the same floor. In addition, import is syntactic sugar and is executed at compile time. The execution process is converted to require. So syntactically, it is not allowed to write import imports (non-import () outside the top part.
require is executed at run time, so it can be written in conditional judgment.

attached:

import router from './router'

 
const options = { }
if(process.env.NODE_ENV === 'router'){
   options.router = require('./router')
}

const vm = new Vue(options)
Menu