Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Helpers for building single-page applications on ASP.NET MVC Core using Vue Cli or Quasar Cli.

License

NotificationsYou must be signed in to change notification settings

EEParker/aspnetcore-vueclimiddleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a stand-alone module to add Vue Cli and Quasar Cli support to AspNet Core.

See the examples here:https://github.com/EEParker/aspnetcore-vueclimiddleware/tree/master/samples

ASP.NET 3.X Endpoint Routing

First, be sure to switch Vue Cli or Quasar Cli to output distribution files to wwwroot directly (not dist).

  • Quasar CLI: regex: "Compiled successfully"
  • Vue CLI: regex: "Compiled successfully" or "running at" or "Starting development server" depending on version

the reason forStarting development server ,the npm-script running checkpoint:Although the dev server may eventually tell us the URL it's listening on,it doesn't do so until it's finished compiling, and even then only if there wereno compiler warnings. So instead of waiting for that, consider it ready as soonas it starts listening for requests.see the codes

Configuration Options

When using theMapToVueCliProxy orUseVueCli you can customize the behavior based on your npm script runner or compiler.

ParameterTypeDescriptionDefault
npmScriptstringThe name of the script in your package.json file that launches the vue-cli, quasar cli or other web server.
spaOptionsSpaOptionsSet the folder of the app to be proxied.
portintSpecify the vue cli server port number. This is also used by the force-kill option to discover processes utilizing the port.8080
httpsboolSet proxy to use httpsfalse
runnerenum { Npm, Yarn }Specify the runner, Npm and Yarn are valid options. Yarn support is experimental.Npm
regexstringIMPORTANT Text to search in npm log that indicates web server is running. ThisMUST BE SET for vue-cli, quasar and quasar v2. (e.g.running at,READY,APP Url)running at
forceKillboolAttempt to kill the npm process when stopping debugging.false
wslboolSet to true if you are using WSL on windows. For other operating systems it will be ignored. This changes the executed process name towsl instead ofcmd.false

SeeMigrating Asp.Net 2.2 to 3.0 Endpoint Routing

publicclassStartup{publicStartup(IConfigurationconfiguration){Configuration=configuration;}publicIConfigurationConfiguration{get;}// This method gets called by the runtime. Use this method to add services to the container.publicvoidConfigureServices(IServiceCollectionservices){// NOTE: PRODUCTION Ensure this is the same path that is specified in your webpack outputservices.AddSpaStaticFiles(opt=>opt.RootPath="ClientApp/dist");services.AddControllers();}// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.publicvoidConfigure(IApplicationBuilderapp,IWebHostEnvironmentenv){// optional base path for IIS virtual app/directoryapp.UsePathBase("/optionalpath");// PRODUCTION uses webpack static filesapp.UseSpaStaticFiles();// Routingapp.UseRouting();app.UserAuthorization();app.UseEndpoints(endpoints=>{endpoints.MapControllers();endpoints.MapToVueCliProxy("{*path}",newSpaOptions{SourcePath="ClientApp"},npmScript:(System.Diagnostics.Debugger.IsAttached)?"serve":null,regex:"Compiled successfully",forceKill:true,wsl:false// Set to true if you are using WSL on windows. For other operating systems it will be ignored);});}}

ASP.NET 2.2 Usage Example

usingVueCliMiddleware;publicclassStartup{publicStartup(IConfigurationconfiguration){Configuration=configuration;}publicIConfigurationConfiguration{get;}publicvirtualvoidConfigureServices(IServiceCollectionservices){services.AddMvc();// etc// Need to register ISpaStaticFileProvider for UseSpaStaticFiles middleware to workservices.AddSpaStaticFiles(configuration=>{configuration.RootPath="ClientApp/dist";});}publicvirtualvoidConfigure(IApplicationBuilderapp,IHostingEnvironmentenv){// your config opts...// optional basepath// app.UsePathBase("/myapp");// add static files from SPA (/dist)app.UseSpaStaticFiles();app.UseMvc(routes=>/* configure*/);app.UseSpa(spa=>{spa.Options.SourcePath="ClientApp";#ifDEBUGif(env.IsDevelopment()){spa.UseVueCli(npmScript:"serve",port:8080);// optional port}#endif});}}

CSPROJ Configuration

You may also need to add the following tasks to your csproj file. This are similar to what are found in the default ASPNETSPA templates.

  <PropertyGroup><!-- Typescript/Javascript Client Configuration-->    <SpaRoot>ClientApp\</SpaRoot>    <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>  </PropertyGroup>  <TargetName="DebugEnsureNodeEnv"BeforeTargets="Build"><!-- Build Target:  Ensure Node.js is installed-->    <ExecCommand="node --version"ContinueOnError="true">      <OutputTaskParameter="ExitCode"PropertyName="ErrorCode" />    </Exec>    <ErrorCondition="'$(ErrorCode)' != '0'"Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />  </Target>  <TargetName="DebugEnsureNpm"AfterTargets="DebugEnsureNodeEnv"><!-- Build Target:  Ensure Node.js is installed-->    <ExecCommand="npm --version"ContinueOnError="true">      <OutputTaskParameter="ExitCode"PropertyName="ErrorCode" />    </Exec>  </Target>  <TargetName="EnsureNodeModulesInstalled"BeforeTargets="Build"Inputs="package.json"Outputs="packages-lock.json"><!-- Build Target: Restore NPM packages using npm-->    <MessageImportance="high"Text="Restoring dependencies using 'npm'. This may take several minutes..." />    <ExecWorkingDirectory="$(SpaRoot)"Command="npm install" />  </Target>  <TargetName="PublishRunWebpack"AfterTargets="ComputeFilesToPublish"><!-- Build Target: Run webpack dist build-->    <MessageImportance="high"Text="Running npm build..." />    <ExecWorkingDirectory="$(SpaRoot)"Command="npm run build" /><!-- Include the newly-built files in the publish output-->    <ItemGroup>      <DistFilesInclude="$(SpaRoot)dist\**" />      <ResolvedFileToPublishInclude="@(DistFiles->'%(FullPath)')"Exclude="@(ResolvedFileToPublish)">        <RelativePath>%(DistFiles.Identity)</RelativePath>        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>      </ResolvedFileToPublish>    </ItemGroup>  </Target>

History

Due to the discussionhere, it was decided to not be included in the Microsoft owned package.

About

Helpers for building single-page applications on ASP.NET MVC Core using Vue Cli or Quasar Cli.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors16


[8]ページ先頭

©2009-2025 Movatter.jp