k-maru / grunt-typescript

MIT License
137 stars 60 forks source link

Is it possible to build commonjs for server and amd for client? #84

Closed psnider closed 9 years ago

psnider commented 9 years ago

I've been unable to figure out how to have different build recipes. I use TypeScript on the server and in the browser, and I have several different builds:

commonjs modules

amd modules

code shared between server and browser

It appears that the value of typescript.base.options.module applies to all sources. Is it possible to configure grunt-typescript to build my project?

k-maru commented 9 years ago

You can be achieved by defining the tasks independent.

e.g.

typescript: {
    server: {
        src: "src/**/*.ts",
        dest: "bin/server",
        options: {
            basePath: "src",
            module: "commonjs"
        }
    },
    client: {
        src: "src/**/*.ts",
        dest: "bin/client",
        options: {
            basePath: "src",
            module: "amd"
        }
    },
    //serverTest ・・・・
    //clientTest・・・・
}

I don't understand english well. If my understanding is wrong, please show me an example in detail.

psnider commented 9 years ago

Thanks, that worked.

For reference, here is the config that I'm now using:

        typescript: {
            server: {
                src: ['src/server/ts/*.ts'],
                dest: 'commonjs',
                options: {
                    module: 'commonjs',
                    target: 'es5',
                    basePath: 'src/server/ts',
                    declaration: false
                }
            },
            server_common: {
                src: ['src/common/ts/*.ts'],
                dest: 'commonjs',
                options: {
                    module: 'commonjs',
                    target: 'es5',
                    basePath: 'src/common/ts',
                    declaration: false
                }
            },
            client: {
                src: ['src/client/ts/*.ts'],
                dest: 'amd',
                options: {
                    module: 'amd',
                    target: 'es5',
                    basePath: 'src/client/ts',
                    declaration: false
                }
            },
            client_common: {
                src: ['src/common/ts/*.ts'],
                dest: 'amd',
                options: {
                    module: 'amd',
                    target: 'es5',
                    basePath: 'src/common/ts',
                    declaration: false
                }
            }
        },