ASP.NET MVC 5 starter project with Vue.js frontend. Single-page application with client-side routing.
*** Full write-up now available *** https://kleypot.com/vue-js-single-page-application-asp-net-mvc-5/
The only dependencies for this template are recent versions of Visual Studio and Node.js.
- Clone the repo
- Build/Debug the project using Visual Studio
Hot Reloading is enabled in this template. Follow these steps for the best Vue.js development experience.
After starting the Visual Studio debugger:
- Run webpack dev server
$ npm run hot
- Open a browser and navigate to
http://localhost:8080
- Edit and save any .vue, .js, or .scss to utilize hot reloading.
This is a single-page application (SPA). The MVC project has a single catch-all route which returns index.html. This html file contains the Vue application which handles the SPA routing using Vue Router.
The MVC project also has an API route for all server-side CRUD operations. These routes are prefixed with /api
. For example, the route /api/movie/index
will activate the Index() action on MovieController. The API actions generally return JSON.
Several npm scripts are available to manage the webpack build:
npm run dev
- generate bundles for developmentnpm run prod
- generate bundles for productionnpm run watch
- generate bundles for development, watch and rebundle on file changesnpm run hot
- run the SPA using webpack dev server with hot reloading (the VS debugger also needs to be started when testing with API routes)npm run sync
- run the SPA using Browsersync for testing in multiple browsers/viewportsnpm run lint
- manually run ESLint (ESlint is automatically run during the dev and prod builds)
The MSBuild process has been modified to automatically run webpack whenever the project is built or published. The automation depends on your selected Build Configuration:
- Debug - runs
npm install
andnpm run dev
, then MSBuild - Release - runs
npm install
andnpm run prod
, then MSBuild - Unit Test - runs MSBuild only to help speed up .NET automated tests
This template also includes ESLint integrated in the webpack build. Building the project will automatically lint the source code. The prod configuration will error out on lint errors, but the dev build will only log warnings. If you have problems with the build, check the output for possible lint errors.