Skip to content
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

Single output file not working. #257

Closed
dbeckwith opened this issue Jun 6, 2015 · 12 comments
Closed

Single output file not working. #257

dbeckwith opened this issue Jun 6, 2015 · 12 comments

Comments

@dbeckwith
Copy link

I'm having an issue with the --out parameter option that's supposed to output everything into one file.
In my Gruntfile.js, in grunt.initConfig I have this configuration:

    ts: {
      options: {
        module: 'commonjs',
        fast: 'never',
        target: 'es5',
        declaration: false,
        sourcemap: false,
        removeComments: true,
        noImplicitAny: false
      },
      main: {
        src: ['src/**/*.ts', 'lib/**/*.ts'],
        out: 'build/main.js'
      }
    }

So it should output to build/main.js right? But instead all I get is a blank file called main.js and each individual file gets compiled in its source folder. For example, I have these files:

build/
lib/
  bla.ts
src/
  test.ts

and I end up with this after compiling (and some cleaning):

build/
  main.js (empty)
lib/
  bla.ts
  bla.js
src/
  test.ts
  test.js

Something I'm doing wrong?

@nycdotnet
Copy link
Contributor

What version of grunt-ts do you have?

@dbeckwith
Copy link
Author

4.1.2

@nycdotnet
Copy link
Contributor

I just created a brand new folder, did npm install grunt-ts, and set up src/test.ts and lib/bla.ts. When I compile using the below Gruntfile.js by running grunt (to get the default), grunt-ts seemingly works correctly by compiling the code in bla.ts and test.ts to build/main.js.

This is the entirety of the Gruntfile.js I just used to test:

module.exports = function(grunt) {
  grunt.initConfig({
    ts: {
      options: {
        module: 'commonjs',
        fast: 'never',
        target: 'es5',
        declaration: false,
        sourcemap: false,
        removeComments: true,
        noImplicitAny: false
      },
      main: {
        src: ['src/**/*.ts', 'lib/**/*.ts'],
        out: 'build/main.js'
      }
    }

  });
  grunt.loadNpmTasks("grunt-ts");
  grunt.registerTask("default", ["ts"]);
};

Here is the relevant part of the output when I run grunt --verbose:

Running "ts:main" (ts) task
Verifying property ts.main exists in config...OK
Files: src/test.ts, lib/bla.ts
Options: allowBool=false, allowImportModule=false, compile, declaration=false, mapRoot="", module="commonjs", noImplicitAny=false, noResolve=false, co
mments=null, removeComments, sourceMap, sourceRoot="", target="es5", verbose=false, fast="never", compiler="", htmlModuleTemplate="<%= filename %>", h
tmlVarTemplate="<%= ext %>", htmlOutDir=null, htmlOutDirFlatten=false, failOnTypeErrors, noEmitOnError=false, preserveConstEnums=false, suppressImplic
itAnyIndexErrors=false, sourcemap=false
Compiling...
Using tsc v1.4.1
"C:\Users\Steve\Documents\GitHub\sampleproj\src\test.ts" "C:\Users\Steve\Documents\GitHub\sampleproj\lib\bla.ts" --removeComments --target ES5 --modul
e commonjs --out "C:\Users\Steve\Documents\GitHub\sampleproj\build\main.js"



TypeScript compilation complete: 1.51s for 2 typescript files

Done, without errors.

Would you please run grunt --verbose for me and post the output?

@dbeckwith
Copy link
Author

I've modified my folder layout slightly since then, but I'm still getting essentially the same thing. Now all of my source files are in one folder, but I still get a blank output file, and individual compiled files in the source directory.

Running "ts:src" (ts) task
Verifying property ts.src exists in config...OK
Files: src/_ref.d.ts, src/cli.ts, src/lambdacalc.ts
Options: allowBool=false, allowImportModule=false, compile, declaration=false, mapRoot="", module="commonjs", noImplicitAny=false, noResolve=false, comments=null, removeComments, sourceMap, sourceRoot="", target="es5", verbose=false, fast="never", compiler="", htmlModuleTemplate="<%= filename %>", htmlVarTemplate="<%= ext %>", htmlOutDir=null, htmlOutDirFlatten=false, failOnTypeErrors, noEmitOnError=false, preserveConstEnums=false, suppressImplicitAnyIndexErrors=false, sourcemap
Compiling...
Using tsc v1.4.1
"/home/sonaxaton/WebstormProjects/lambdacalc/src/_ref.d.ts" "/home/sonaxaton/WebstormProjects/lambdacalc/src/cli.ts" "/home/sonaxaton/WebstormProjects/lambdacalc/src/lambdacalc.ts" --sourcemap --removeComments --target ES5 --module commonjs --out "/home/sonaxaton/WebstormProjects/lambdacalc/bin/lib.js"



TypeScript compilation complete: 2.58s for 3 typescript files

@nycdotnet
Copy link
Contributor

Ah ok I know what this is. TypeScript doesn't allow external modules to be concatenated with --out, but they don't provide a warning either. Take a look here: microsoft/TypeScript#1544

We should probably provide a warning if a module system is used with out since tsc doesn't.

@nycdotnet
Copy link
Contributor

This will be in the next major version of grunt-ts:

usingoutwithexternalmodules

@dbeckwith
Copy link
Author

Ah okay, thanks!

@nycdotnet
Copy link
Contributor

Check out Browserify or WebPack to do the concatenation. Thank you for the report.

@DerToti
Copy link

DerToti commented Dec 8, 2015

Shouldn't be this working now with module amd and --outFile? (see here)
Is this supported by grunt-ts? I wanted to have grunt-ts (tsc) to concatenate the files.

@nycdotnet
Copy link
Contributor

They are adding concatenation of AMD and SystemJS modules to TypeScript 1.8 I think. Tsc 1.7 and lower can't do it yet. We plan to remove the warning in a future version.

@DerToti
Copy link

DerToti commented Dec 9, 2015

ah ok thx for the information :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants