Setting up a non-SPA project with Visual Studio 2017 for Asp.Net Core 2.1 using TypeScript and Vue

I've been diving deep into research for the past few weeks to set up a new project that utilizes the latest versions of Visual Studio, Vue, TypeScript, and .Net Core as of today (05/15/2018). I'm not looking to create a single page application this time around. Instead, my .cshtml pages will include a tag that loads the specific file for each page. Perhaps I'll integrate Vue and/or Require.js?

I'm facing some challenges configuring Visual Studio to transpile .ts files into .js files, using the new ES6 coding styles with 'require' and the like.

I've tried incorporating some helpful links such as this one and another here. It seems like maybe .Net Core 2.1 has introduced some changes? I'm used to working with traditional .js files only. There are numerous mentions of Visual Studio Code, but unfortunately, that's not an option in this case.

This task should be straightforward. NPM tends to download a lot into the project, but if it does the job, I'll take it. I'm feeling frustrated here. What I really need is a step-by-step guide, starting from creating a new VS project all the way to setting up the tsconfig.json and Webpack.config.js (if that's the best approach) to have a simple Vue app displaying "way to go dumbass!" - or anything at this point. First two beers on me for anyone who can provide me with a detailed guide or direct me to a resource that meets my requirements in the current versions.

Thank you!

Answer №1

If you're looking for a great development experience, I highly recommend using Vue CLI 3 in combination with Microsoft.AspNetCore.SpaServices.

Here are the steps to get started:

  1. dotnet add package Microsoft.AspNetCore.SpaServices
  2. npm install -D aspnet-webpack
  3. npm install -D webpack-hot-middleware
  4. Add the Webpack middleware to your project
if (env.IsDevelopment())
{
    app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
        HotModuleReplacement = true,
        HotModuleReplacementClientOptions = new Dictionary<string, string> { 
            { "reload", "true" }, 
        },
        ConfigFile = "node_modules/@vue/cli-service/webpack.config.js",
    });
}

I am currently exploring how to enable HotModuleReplacement without reloading.

  1. Depending on your configuration in vue.config.js, you can include JavaScript and CSS files in your _Layout.cshtml file like this:
<environment names="Development">
    <script src="~/app.js" asp-append-version="true" type="text/javascript"></script>
</environment>
<environment names="Production">
    <script src="~/bundle/js/chunk-vendors.js" asp-append-version="true" type="text/javascript"></script>
    <script src="~/bundle/js/app.js" asp-append-version="true" type="text/javascript"></script>
</environment>
  1. To improve intellisense support, consider organizing your Vue files as follows. This setup works seamlessly with extensions like Vetur for VSCode or similar tools for VS2017.

Example structure for MyComponent.vue:

<template>
  ...
</template>

<style lang="scss" scoped>
  ...
</style>

<script lang="ts" src="./MyComponent.ts">
</script>

Sample content for MyComponent.ts:

import { Component, Vue } from "vue-property-decorator";

@Component
export default class MyComponent extends Vue {
  ...
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What steps should I take to create an Onboarding/Walkthrough page using Angular Material Design?

Looking for guidance on creating an Onboarding/Walkthrough in Angular Material Design for Electron. As a newcomer to Angular, I'm aiming for a desktop application similar to the image provided. It should showcase several images and offer page navigat ...

Error: The binding element titled implicitly possesses a type of 'any'

Encountering the following issue: ERROR in src/components/Header.tsx:6:18 TS7031: Binding element 'title' implicitly has an 'any' type. 4 | 5 | 6 | const Header = ({title}) => { | ^^^^^ 7 | return( 8 | ...

Programmatically configure filter settings for vue-good-table

Is it possible to dynamically change the displayed value in UI filter elements (such as input fields and dropdowns) within vue-good-table? For instance, if I were to execute the following code: this.$set(this.table.columnsFilters, 'name', ' ...

Using Vue to confirm the absence of a record within a nested v-for loop

I am currently working on creating a table that displays items in rows (first v-for), locations in columns (second v-for), and item_locations in the cells (third -v-for). If an item is present at a certain location (indicated by the presence of an item_lo ...

Troubles with implementing child routes in Angular 6

I'm having trouble getting the routing and child routing to work in my simple navigation for an angular 6 app. I've configured everything correctly, but it just doesn't seem to be working. Here is the structure of my app: └───src ...

Escape from the abyss of callback hell by leveraging the power of Angular, HttpClient, and

I'm currently grappling with understanding Angular (2+), the HttpClient, and Observables. I'm familiar with promises and async/await, and I'm trying to achieve a similar functionality in Angular. //(...) Here's some example code showca ...

"Here's how you can mark an option as selected in Angular, either from the component or the HTML file

When it comes to my form, I have a select menu that sends data to an SQL database and then fetches it back when it is called for editing. The value being edited should be displayed in the select menu option as selected. Here's a peek at my code: < ...

What is the reason for the `Function` type not functioning properly when trying to input a function as a parameter in a higher-order function?

Looking to create a function that requires the following inputs: an array a filter logic function (predicate function) In JavaScript, you can use the following code successfully: const myFilter = (func, arr) => arr.filter(func) const myArr = [1, 2, 3, ...

Using TypeScript to define a constant array as a type

I've hit a roadblock in my typescript project while trying to define a suitable type. Here's the setup: Within my project, I have the following constant: export const PROPERTYOPTIONS = [ { value: "tag", label: "Tag" }, { ...

Unlocking the power of React using TypeScript for optimal event typing

I need assistance with properly typing events in TypeScript. Consider the following function: import * as React from 'react'; someHandler = (event: React.SyntheticEvent<HTMLInputElement> | React.KeyboardEvent<HTMLInputElement>) =&g ...

If a component does not have a specified return type annotation, it will default to an 'any' return type

I'm struggling to understand the typescript error that keeps popping up, it says: 'MyGoogleLogin', which doesn't have a return-type annotation, is being given an implicit 'any' return type. All I want is for the component t ...

Loading components in an Angular CLI project with the base URL

I recently created an Angular CLI project with various components and transferred it to my school's domain using FileZilla. However, I am looking for a way to automatically redirect the application to the HomeComponent upon loading instead of the AppC ...

Troubleshooting why Vue.js isn't updating the DOM with two-way binding

I'm currently utilizing Vue.js for implementing two-way binding. One issue I am facing is with an edit button that should convert a text field into an input field upon clicking. However, the DOM does not update immediately as expected. For instance: ...

Is it possible to remove a complete row in Angular 2 using Material Design

JSON [ { position: 1, name: 'test', value: 1.0079, symbol: 'HHH' }, { position: 2, name: 'test2', value: 4.0026, symbol: 'BBB' }, { position: 3, name: 'test3', value: 6.941, symbol: 'BB' }, ...

Unable to import JSX/TSX component from a separate React application into my primary React application

I find myself facing a challenge with integrating two React applications with different setups. Background: I was assigned the task of developing a design system using ReactJS that would be implemented in their primary application. Despite my limited kn ...

Displaying a React component within a StencilJS component and connecting the slot to props.children

Is there a way to embed an existing React component into a StencilJS component without the need for multiple wrapper elements and manual element manipulation? I have managed to make it work by using ReactDom.render inside the StencilJS componentDidRender ...

Explaining the data link between a service and component: understanding Subject and BehaviorSubject

Can someone explain the concepts of Subject and BehaviorSubject in Angular to me? I'm new to Angular and struggling to understand. I've tried searching online, but I still can't grasp how they work. The same goes for Observable and Observer ...

What are some ways to conceal the v-btn component?

btn : false <v-btn value="false">1</v-btn> <v-btn v-model="btn">2</v-btn> I need to conceal the v-btn component. However, both v-btn 1 and 2 remain visible. Is there a solution for this issue? Thank you. ...

Vue CLI Plugin Electron Builder displays a completely empty screen after compiling

After building my electron app using this specific plugin, I encountered a frustrating issue where the installed package would only display a blank, white screen. Despite setting up the window to open dev tools in the built version, inspecting the page rev ...

Having trouble making optional parameters overload in Typescript?

Let's consider a simplified instance (although overloading may not be necessary in this case due to the simplification) UPDATE: The initial example provided did not fully illustrate the issue, so here is an improved version: function fn <T>( / ...