14

I want to start playing with Aurelia and MVC 6 Web API with Visual Studio 2015 RC, and I'm using OdeToCode's blog post as a starting point.

I understand the idea behind the new wwwroot folder, but I'm basically confused as to what should or shouldn't put in there.

My initial thought would to install all jspm packages as well as the actual JavaScript source files outside the wwwroot folder, and then copy with gulp everything that's necessary for running while developing or bundle and copy when deploying.

It would look something like this:

enter image description here

But then again, should I place index.html also in the src folder? and config.js? Or am I actually making my life difficult for myself and should just develop from within the wwwroot folder?

It's the jspm packages that confuse me; it feels wrong to have such a large amount of JavaScript files in the wwwroot when I plan on bundling and minifying anyway.

In short: What would be the preferred folder structure for an Aurelia ASP.NET 5 app in Visual Studio 2015?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sergi Papaseit
  • 15,999
  • 16
  • 67
  • 101
  • I'd keep jspm_packages outside of wwwroot if you are building and bundling. I'd only keep static assets that are served from the file system in wwwroot. – OdeToCode May 09 '15 at 11:50
  • Thanks @OdeToCode, that was my feeling too, but that means I need to bundle as well every time I run the application while developing, am I right? – Sergi Papaseit May 09 '15 at 11:52
  • Yeah, it is a trade off. You should be able to use StaticFiles middleware if you want to serve directly from another folder outside of wwwroot, even if only for development / debug. – OdeToCode May 09 '15 at 12:00
  • Thanks again. You might want to consider adding this as an answer, by the way ;) and, if you're feeling generous, maybe and example on how to achieve serving from outside wwwroot with StaticFiles :p – Sergi Papaseit May 09 '15 at 12:10
  • 1
    Seems like a lot of work for something that simple, why do you care about your jspm-folder? Just keep it in wwwroot, it is not going to get downloaded by the client anyway, so why bother with gulp? The only purpose I see gulp gulp for in Visual Studio is bundling and minification and that is only when deploying to production. Don't be confused by other developers not using VS and their need to deploy to their local web server. – Janus007 Jul 18 '15 at 17:46

1 Answers1

9

I spent quite some time on this and finally settled on:

  • ApplicationName
    • src
      • Api
        • In here I have an ASP.NET 5 project that provides the api to be consumed by the Aurelia app. You will likely need to turn on CORS to avoid errors.
      • Client.Web
        • In here I started with the Aurelia skeleton navigation app. We changed the dist folder to wwwroot. The jspm_packages folder sits outside the wwwroot and the gulp tasks that come with the skeleton navigation app take care of all the copying to wwwroot as needed.

This approch gave me the following benefits:

  • Clean separation of the api and the client code.
  • Option to deploy the api and client separately.
  • Ability to leverage all of the gulp tasks that come with the skeleton navigation app
  • Clear place to switch over to the Javascript file naming conventions (camelCase)

The drawbacks of this approach:

  • Starting the full app is more difficult. Currently, I have to click "Play" in Visual Studio to start the api, then I have to start gulp watch. This is not too big of a deal because you can mostly leave gulp watch running the entire time you develop.
Josh Graham
  • 1,188
  • 12
  • 17
  • 3
    Familiar with the [Task Runner Explorer](https://visualstudiogallery.msdn.microsoft.com/8e1b4368-4afb-467a-bc13-9650572db708)? You can attach some steps before or after building, cleaning and some others. You can attach `gulp watch` on your after build event, one less manual step ;-) – Andrew May 12 '15 at 20:17
  • 1
    @Andrew yes, I have experimented with Task Runner Explorer, and it is nice. Ideally, `gulp watch` would not run on `build` but on `run` but `run` is not an option that I know of. You _can_ use any of the dnx commands from `project.json` from the "play" button, so you could start multiple projects in one step that way. Problem is, I have yet to find a way to start a gulp task from the `commands` section of `project.json`. – Josh Graham May 13 '15 at 00:31
  • "Currently, I have to click "Play" in Visual Studio" Use IIS Pro or run owin on windows service with topshelf library. – Elisabeth May 25 '15 at 15:34
  • @JoshGraham, you probably had to create a `gulp` task to copy `jspm_packages/system.js` and other files to `wwwroot` in order for the Aurelia skeleton to run, didn't you? What did you instruct the gulp to copy? Everything inside the `jspm_packages` folder? If not, care to share that task in your answer? – Sergi Papaseit May 28 '15 at 20:01
  • @SergiPapaseit I did not have to create a gulp task to copy any jspm_packages to wwwroot. The Aurelia skeleton navigation comes with a gulp command called `gulp watch` that serves the _project_ root not _wwwroot_ (or dist if you did not rename it). I wanted everything to be copied to wwwroot when I built the project, but Visual Studio kept crashing when the jspm_packages folder was copied so I am currently just letting it serve out of the project root and plan to revisit when a new version of Visual Studio ships. – Josh Graham Jun 01 '15 at 14:49
  • can you screen shot your project structure like the OP did? I am curious to see what it looks like in Visual Studio – Evan Larsen Aug 29 '15 at 17:25
  • I had a similar problem with jspm_packages in VS, specifically because it was trying to add all the files to source control (tfs). The project was a web project which by default contains all files, one solution was to make the jspm_packages folder (and npm) not visible within windows. A better solution which we went with was to make the project a console app which allowed us to explicitly exclude the folder from the project. Visual Studio Code managed it better, but TFS integration was not available I think. – Dan Wray Oct 07 '15 at 14:01