Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(javascriptservices): update for .net core 2.0 #741

Merged
merged 3 commits into from
Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/commands/new/project-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ exports.ProjectTemplate = class {
this.content
),
ProjectItem.resource('appsettings.json', 'content/javascriptservices/appsettings.json').skipIfExists(),
ProjectItem.resource('global.json', 'content/javascriptservices/global.json').skipIfExists()
ProjectItem.resource('global.json', 'content/javascriptservices/global.json').skipIfExists(),
ProjectItem.resource('webpack.netcore.config.js', 'content/javascriptservices/webpack.netcore.config.js').skipIfExists()
);

return this;
Expand Down
13 changes: 6 additions & 7 deletions lib/resources/content/javascriptservices/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

namespace WebApplicationBasic
Expand All @@ -11,14 +12,12 @@ public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();

host.Run();
}
}
}
25 changes: 11 additions & 14 deletions lib/resources/content/javascriptservices/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ namespace WebApplicationBasic
{
public class Startup
{
public Startup(IHostingEnvironment env)

public Startup(IConfiguration configuration)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
Configuration = configuration;
}

public IConfigurationRoot Configuration { get; }
public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
Expand All @@ -35,15 +31,16 @@ public void ConfigureServices(IServiceCollection services)
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();

app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
HotModuleReplacement = true
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true,
ConfigFile="webpack.netcore.config.js",
HotModuleReplacementClientOptions = new Dictionary<string,string>{
{"reload", "true"}
}
});
}
else
Expand Down
15 changes: 12 additions & 3 deletions lib/resources/content/javascriptservices/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
ViewData["Title"] = "Home Page";
}

<div aurelia-app="boot">Loading...</div>
<div aurelia-app="main">Loading...</div>

@section scripts {
<script type="text/javascript" src="~/dist/vendor.js" asp-append-version="true"></script>
<script type="text/javascript" src="~/dist/app.js" asp-append-version="true"></script>
<environment names="Development">
<script type="text/javascript" src="~/dist/vendor.bundle.js" asp-append-version="true"></script>
<script type="text/javascript" src="~/dist/app.bundle.js" asp-append-version="true"></script>
</environment>
<environment names="Production">
<script type="text/javascript" asp-src-include="~/dist/common.*.bundle.js" asp-append-version="true"></script>
</environment>
<environment names="Staging, Production">
<script type="text/javascript" asp-src-include="~/dist/vendor.*.bundle.js" asp-append-version="true"></script>
<script type="text/javascript" asp-src-include="~/dist/app.*.bundle.js" asp-append-version="true"></script>
</environment>
}
2 changes: 1 addition & 1 deletion lib/resources/content/javascriptservices/global.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"sdk": { "version": "1.0.1" }
"sdk": { "version": "2.0.0" }
}
26 changes: 14 additions & 12 deletions lib/resources/content/javascriptservices/project.csproj
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<!-- Files not to show in IDE -->
<None Remove="yarn.lock" />
</ItemGroup>
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" />
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
<Exec Command="node node_modules/webpack/bin/webpack.js --env.prod" />

<Exec Command="au build --env prod" />
<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="wwwroot\dist\**" />
Expand All @@ -30,4 +32,4 @@
</ResolvedFileToPublish>
</ItemGroup>
</Target>
</Project>
</Project>
16 changes: 16 additions & 0 deletions lib/resources/content/javascriptservices/webpack.netcore.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const webpackConfig = require('./webpack.config');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
var originalConfig = webpackConfig({});

module.exports = () => {
let config = { ...originalConfig };
config.output.filename = '[name].bundle.js';
config.output.publicPath = '/dist/';
config.plugins.splice(config.plugins.indexOf(HtmlWebpackPlugin));
config.plugins = [
new CleanWebpackPlugin([config.output.path]),
...config.plugins
];
return config;
};