Search code examples
vue.jsvue-cli-3

mode in project building in vue js


i have two env files in my vue js project

- .env.development
- .env.production

i want to build the project with command npm run build --mode development or npm run build --mode production for build based on my env files based on vue docs.

and i get this error

Entry module not found: Error: Can't resolve '/var/www/html/projectname/production' in '/var/www/html/projectname'

what is the solution??


Solution

  • Your file setup seem correct, it looks like you need to change your command from this:

    npm run build --mode production
    

    to this

    npm run build -- --mode production
    

    According to this github thread: https://github.com/vuejs/vue-cli/issues/1528#issuecomment-395970443

    Copying the comment there:

    "In other words: all arguments before -- are interpreted as arguments for npm itself, not the script you are running."


    Alternatively, if you don't use the npm script shortcut, you can use vue-cli-service directly:

    vue-cli-service build --mode production