Skip to content

Commit

Permalink
fix(javascriptservices): update for .net core 2.0
Browse files Browse the repository at this point in the history
The webpack build was broken with .net core 2.0
The SpaServices middleware is incompatible with the cli webpack config
This adds a config file for webpack that fixes it and was added to the
new project build.

Realtes to issues #734 and #701, clean-webpack-plugin needs to be
installed otherwise webpack gets stuck in a rebuilding loop
see webpack/watchpack#25 and referenced issues
  • Loading branch information
grufffta committed Sep 4, 2017
1 parent cdadbe1 commit f41af63
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
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
12 changes: 8 additions & 4 deletions lib/resources/content/javascriptservices/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace WebApplicationBasic
{
public class Startup
{

public Startup(IConfiguration configuration)
{
Configuration = configuration;
Expand All @@ -34,9 +34,13 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
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
14 changes: 11 additions & 3 deletions lib/resources/content/javascriptservices/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
<div aurelia-app="main">Loading...</div>

@section scripts {
<script type="text/javascript" asp-src-include="~/dist/common.*.bundle.js" asp-append-version="true"></script>
<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 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>
}
6 changes: 3 additions & 3 deletions lib/resources/content/javascriptservices/project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
Expand All @@ -18,11 +19,10 @@
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
<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 Down
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;
};

0 comments on commit f41af63

Please sign in to comment.