Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

vue-cli-plugin-express

mathieutu265MIT1.0.2

vue-cli 3 plugin to add an Express Api

vue, vue-cli, express, api

readme

vue-cli-plugin-express

npm npm vue-cli3

:rocket: Add an API in your Vue application in 2 minutes!

This is a vue-cli 3.x plugin to add an Node Express server in your Vue project.


screenshot


:star: Features:

  • Included fully customizable Express Server:
    • Just add your api routes into your project (with import/export support) without thinking to something else.
    • Optional automatic fallback to the Vue app, to serve both the api and the application with only one command.
    • Optional socket.io support.
  • (soon) Included optional example routes and components.

Table of contents


Getting started

:warning: Make sure you have vue-cli 3.x.x:

vue --version

If you don't have a project created with vue-cli 3.x yet:

vue create my-new-app

Navigate to the newly created project folder and add the cli plugin:

cd my-new-app
vue add express

Soon: :information_source: An example APIExample.vue component will be added into your sources if you chose to include the examples.

Usage

To start your server for development purpose, use this commands:

yarn express

The server will be automatically restarted when a change is detected.

You just then have to start the app:

yarn serve

To run the server only once for production use, run:

yarn express:run

Updating vue-cli-plugin-express will update the Express server service :+1:

Injected Commands

  • vue-cli-service express:watch

    Run the Express server with info from ./srv and watch the files to restart itself automatically.

  • vue-cli-service express:run

    Run the Express server with info from ./srv once.

Configuration

The Express Server can be configured via the pluginOptions in vue.config.js:

module.exports = {
  // Other options...
  pluginOptions: {
    // Express-related options
    express: {
        shouldServeApp: true,
        serverDir: './srv',
      },
    },
  },
}

Use your app in production

Move @vue/cli-service from devDependenciesto dependencies.

Execute the following commands:

yarn build
yarn express:run

For most of cloud hosting services, you can add a start command that will be triggered automatically:

{
  "scripts": {
    "start": "yarn express:run" 
  }
}

changelog

Changelog

1.0.2 (2019-07-12)

Fixed

  • 🐛 Pass host to server.listen method. (#18) [366429c]

Miscellaneous

  • 👷‍♂️ Add automatic publishing with CI. [06fdd1f]
  • 📦 Update packages. [dae8fed]

1.0.1 (2019-04-27)

Fixed

  • 🐛 Fix the esm version because of #14. [14ccf5e]

Documentation

  • 📝 Update production launch doc (fix #1). [cc70895]

1.0.0 (2019-02-11)

Added

  • ✨ Expose http binding to client application (#10) [4e3771a]
  • 📄 Add License. [311e882]
  • 📝 Add Changelog. [b3072ec]

Fixed

  • 🐛 Fix wrong usage of hasYarn function. (fix #6) [aef3176]
  • 🐛 Add .idea to .npmignore. (fix #4) [1f5d9ab]
  • 🐛 Fix error handling (fix #3) [f7e1c2b]
  • ✏️ Fix typo in success message. (fix #5) [1226449]
  • 📝 Fix command name in Readme. [aa738af]
  • 📝 Fix command name [0736da0]

0.0.4 (2018-10-08)

Fixed

  • 🐛 💄 Fix bug in generator and server and increase DX. [16e0a11]

0.0.3 (2018-10-08)

Fixed

  • 🐛 Fix bug with prompts. [4d738d4]

0.0.2 (2018-10-06)

Added

  • ✨ Add the server main features. [32d3800]
  • 🎉 Package initialisation. [d15ec62]