-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Suggestion: TypeScript Library Project in Visual Studio #11
Comments
This would be excellent as a standalone compiler feature. As it stands, my multiple AMD module projects are compiled into a single JS file using the RequireJS compiler, but there's no way to automatically tell the TypeScript compiler to do the same for their declaration files (you end up with one My use case is that one module ends up being the exported 'frontend' in a global variable, from which all library functionality is exported. If this is the common case, then perhaps TypeScript could support a command line option for emitting a Namespacing might be an issue here when you are using 100% AMD/CommonJS modules; I haven't thought too deeply about it yet. |
This is somewhat related to #293 as that also aims to help using library projects.
To me this wouldn't be a feature I'd use, as one of the advantages for using typescript library projects (specified with a custom path) would be that I only use the classes/modules that I need, there's no point packing everything together when I may only use one small feature of it. |
I would love to see a dedicated project type for TypeScript in Visual Studio that handles references and copying of output around automatically, in much the same way that a C# project automatically copies around it's assemblies. Currently I have the following:
To make this all work I have to:
The problems with this are:
Minor problems:
Now it maybe that I'm not setting these projects up correctly and some of these things can be fixed. (s seems like it should be fixable for instance) But in an ideal world there would be a dedicate project type for TypeScript that solves all this automagically for me. The project would:
That's how I see it working anyways, hope it helps. Happy to give more detail and help out if you want, get in touch. |
Wouldn't the simplest solution be for Visual Studio to support the new .tsconfig file? A simple TypeScript only project that uses this new file to drive the settings for the compiler. Debugging would be supported using source maps. I'm not sure we need a new way to do package sharing/references over and above the normal web way of using npm and browserify etc... |
You say 'normal web way'... But that's not what I'd consider normal... So from my point of view, this is what's happened.
That's normal from my point of view. :) Now if I'm supposed to be using Node and NPM and Browersify and so on, that's fine. Happy to go with the norm. Where is that documented though? I can't see anything on typescriptlang.org or the Visual Studio docs about setting up TypeScript projects in VS and using NPM and the like. I've done a lot of web searching about TypeScript projects without much luck. Also if its the norm then why doesn't the website/TypeScript projects in Visual Studio use all that stuff already? Maybe that's the answer - change those projects (or create new ones) that use this NPM/Browserify approach. Also with NPM - would I also then be in a position where I have to use NPM as my package manager for JavaScript stuff and NuGet for the rest? That would suck! Sorry if that sounds like I'm moaning, I'm really not. Just as a relative newbie to TypeScript setting all this stuff up has proved hard for me so if we could make it easier for other newbies that would be great. And if one of you could tell me the answer to my problems then that would be even better still. :P |
@MrKWatkins, as far as I know there is no way to mix ASP.Net/Nuget and npm. If you want to use npm in Visual Studio then I suggest trying out NTVS. They have a lovely set of tools (interactive Node.js window, test harness, debugging) that integrate well with Visual Studio. They also have an npm UI: I was hoping for something similar for TypeScript. @paulvanbrenk seemed to suggest that the TypeScript team is working with the NTVS team. Haven't seen anything yet. |
Thanks @NoelAbrahams. I don't really want to use NPM to be honest, I'd just be prepared to if it solved my problems. Or if it was the accepted way of doing things. I'd really much prefer a TypeScript project as a first class citizen, with all my references and debugging automagically working. |
Perhaps the following two issues should be subsumed under here:
|
👍 Came here to suggest this feature. Found this issue already created. |
@MrKWatkins, Another similar approach, debugging with mappings works for the setup I have. Currently, I'm working with website projects as you discussed, and inserting links to typescript files I wish to access in my main site, this can be done just fine using the project explorer, using "Insert Existing Item" and then choosing "Add As Link". Your .csproj file then looks something like: <ItemGroup>
<TypeScriptCompile Include="..\..\Test.ts\Test.ts\Assert.ts">
<Link>Scripts\Assert.ts</Link>
</TypeScriptCompile>
...
</ItemGroup> At the bottom of my project file is I've then included some post build actions to copy across the linked, and generated files: <Target Name="CopyLinkedContentFiles" AfterTargets="Build">
<Copy Condition="'%(TypeScriptCompile.Link)' != ''" SourceFiles="%(TypeScriptCompile.Identity)" DestinationFiles="%(TypeScriptCompile.Link)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true"/>
<Copy Condition="'%(TypeScriptCompile.Link)' != ''" SourceFiles="@(TypeScriptCompile -> '%(RootDir)%(Directory)%(Filename).js')" DestinationFolder="$([System.IO.Path]::GetDirectoryName(%(TypeScriptCompile.Link)))" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" />
<Copy Condition="'%(TypeScriptCompile.Link)' != ''" SourceFiles="@(TypeScriptCompile -> '%(RootDir)%(Directory)%(Filename).js.map')" DestinationFolder="$([System.IO.Path]::GetDirectoryName(%(TypeScriptCompile.Link)))" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" />
</Target> This then pulls down the typescript, and their counterpart javascript and map files to the linked location. This will only work for the default build behaviour though, without combining, and without code redirecting. Linking with recursion should be possible, not that I've tested it. I don't know if would be possible to do, but it would be fantastic if referencing an assembly from within a project would trigger some msbuild magic to inspect the project file of the referenced assembly, instead of manually linking directly. |
If you're taking this idea all the way allow a symbol package with the .ts files and one giant js..map to map the minified combined js back to the ts files.+ |
@SilentPenguin I did initially use links but I had various problems with it. Sadly can't remember the details now, it was a while ago... |
I don't think that a TypeScript project system using MSBuild makes sense because there are so many ways to build JavaScript projects (gulp, grunt, broccoli, ...). It would be nice to have a simple project system that supports the new Task Runner Explorer like the ASP.NET 5 project system does and shows all files in the folder except some folders (node_modules, bower_components, ...) that can be defined by the user. |
@Lenne231 TypeScript has no project system. you can just use any project you like.. there is not really anthing as "TypeScript Project". if you want to use an ASP.net5 project and add typescript files, use grunt/gulp to build nothing would block you. the only missing piece that we are working on, is the support for tsconfig.json in VS. this should be available in the next public release of VS2015. |
@mhegazy The problem is that i don't need ASP.NET 5 and don't want to write Universal Apps in JavaScript or something like that. I'm currently using gulp, but there is no plain JavaScript project type. |
I just want to be able to open a folder with my TypeScript library project in Visual Studio, and, ideally, have the ability to build it (using whicheverflavor-of-the-month JS build tool I prefer), run unit tests, and debug it. Right now, that's not possible without making an ASP or Universal App project. I realize there's a number of practical concerns here, such as where to draw the line regarding intricate build setups and folder structures, which is complicated by the fact that there are multiple types of JS modules. But as of right now, there's no Visual Studio story for JS/TS-only library projects, although right now Visual Studio Code does all of these things for free, so maybe it's no longer a concern. 😄 |
Yes, Visual Studio Code looks promising, but i'm using F#/Suave. I don't need web tooling in the F# project, but it would be nice to have a plain JavaScript project beside the F# project for the client side code. |
I created a workflow a few weeks back that provides the concept of a typescript library project. Granted, my implementation runs on node/gulp, but there's no reason the idea couldn't be ported to another build system. The idea is essentially, you expose the code to the language service in one way and pass the code to the compiler in another. The code is here if you're interested - https://github.com/kungfusheep/ts-internal-module-workflow I'm not proposing this as a solution, I've just found it to be a better approach to working with code over say 7-8 different projects/libraries. On Tue, Jun 9, 2015 at 7:24 PM, Lennart notifications@github.com wrote:
|
Library projects would be awesome!!! |
It would be awesome! +1 |
+1 would be great to have that. |
I created a project structure, using visual studio 2015 and aspnet empty website template - which means that it has some dnx and website stuff that is not needed. But I got a working library project for my needs. https://github.com/s-innovations/S-Innovations.PortalFramework I can distribute the library using bower, (currently i just Key points from creating a library template, which i currently use yeoman to create a new project with by running "yo si-portal" (generator project https://github.com/s-innovations/generator-si-portal-framework)
3.sync/copy all the required files to dist/src that is needed from my other projects that will pull in this library.
Since I will from my other projects use requirejs as module loader and build tool to combine and minify javascript files this was sufficient. I also created a demo project that consumes my library. Anyway - my library is not for production and I just used it to learn and get a overview of how I want to structure my typescript projects moving forward. And using yeoman and bower seems like a good starting point to me. Feel free to create issues in any of the projects to discuss or provide feedback - maybe some of the information is usefull to others who start working with typescript projects. |
Poke |
+1 - Just want a VS "Typescript Shared Library" project type that has the same .ts -> .js compilation on save, and "Typescript Build" properties tab as the "HTML Application with Typescript" project type, but doesn't need to be an application. Otherwise, the .tsconfig approach sounds cleanest; all the gulp/npm stuff is just adding an unnecessary layer of extra tooling. |
Is there still any value in this proposal, now that |
I still think that there is value in this proposal. Of course it is possible to do something like that with grunt/gulp, but an integrated wy would be nice. |
+1. My use case is having some library code written in TS that I want to include in the output of several other The code needn't leave my solution. Setting up a local npm repo for this seems like overkill, and would be inconvenient when changes are made. If there's an alternative approach that solves this, I'd like to hear about it. |
+1. A workaround today is to use separate folders for each and one of your "ts projects" and let each folder contain its own .tsconfig json with outFile specificed. If you do this inside an asp.net web core project in the correct way you will even get debugging support on all "sub projects" if you emit sourceMaps. |
Wow it's been 5 years since this was proposed. @RyanCavanaugh any chance there have been recent talks about supporting this scenario? What I'm looking for is I'd like to have a typescript project shared between multiple asp.net+angular apps as a project with the ability to of course step in if neccessary |
Still Not implemented in VS2019 16.3.3 / TS 3.6.3 It should be interesting to have ts and cs files in a netstandard or core library |
I'm closing this one in favor of #14533 to keep the conversation there. |
Create a project template and project system support for a TypeScript 'library'
Library project outputs would include a .d.ts and a .js file; referencing projects would consume the .d.ts file automatically and have separate compilation. Refactoring in the referenced project would be reflected in any loaded referencing projects.
The text was updated successfully, but these errors were encountered: