Igor Marenkov
Igor Marenkov

Reputation: 125

visual studio individual settings for typescript file

In my visual studio project properties I have enabled checkbox "Combine JavaScript output into file". Can I exclude some typescript files from this output? I want compile this (excluded) files to individual js files.

Upvotes: 3

Views: 547

Answers (2)

Igor Marenkov
Igor Marenkov

Reputation: 125

The solution in my case is modify csproj:

  1. Change file target from
 <TypeScriptCompile Include="file.ts" />

to

 <CustomTypeScriptCompile Include="file.ts" /> 
  1. Add "CustomTypeScriptCompile" target:
    <PropertyGroup>
    <CustomCompileTsFiles>@(CustomTypeScriptCompile->'%(FullPath)')</CustomCompileTsFiles>
    <SplitedCompileTsFiles>$(CustomCompileTsFiles.Replace(';', ' '))</SplitedCompileTsFiles>
    </PropertyGroup>

    <Target Name="CustomTypeScriptCompile" BeforeTargets="Build">
    <Exec Command="tsc $(SplitedCompileTsFiles) --sourcemap -t ES5" />
    </Target>

Upvotes: 3

TSV
TSV

Reputation: 7641

Unfortunately, you can not do it via VS project and .ts files settings.

You can use grunt task runner extension (described in the article) + grunt-typescript plugin for custom TypeScript build task, "gruntfile.js" sample content:

grunt.initConfig({
    typescript: {
        buildmodules: {
            src: ['modules/*.ts'],
            dest: 'bin/modules.js',
            options: {
                module: 'amd', //or commonjs
                target: 'es5', //or es3
                basePath: 'path/to/typescript/files',
                sourceMap: true,
                declaration: true
            }
        },
        tests: {
            src: ['Tests/*.ts'],
            dest: 'bin/tests.js',
            options: {
                module: 'amd', //or commonjs
                target: 'es5', //or es3
                basePath: 'path/to/typescript/files',
                sourceMap: true,
                declaration: true
            }
        }
    }
});

grunt.loadNpmTasks("grunt-typescript");

Also you can use Web Essentials extension for bundling separate .js files produced by TSC.

Upvotes: 0

Related Questions