mseddon
mseddon

Reputation: 1885

Problems building a closure-compiler/typescript front end workflow

I'm trying to build a useful workflow using gulp, closure-compiler and typescript using npm modules hosted from a private sinopia repository.

The end goal is the following:

(Closure compiler is not optional, UglifyJS does not perform the level of optimizations I want in terms of file size and performance)

This is all working perfectly when my project is entirely self contained in my source tree (i.e. I haven't npm installed any modules. Here is the working gulpfile:

var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var size = require('gulp-size');
var server = require('gulp-live-server');
var typescript = require('gulp-typescript');
var closureCompiler = require('gulp-closure-compiler');

/** No minification */
gulp.task('compile-dev', function() {
    console.log("compile-dev at "+new Date())
    var b = browserify({baseDir: "src", debug: true})
        .add("src/main.ts")
        .plugin('tsify', { noImplicitAny: true, target: "es6"});
    b.bundle()
    .on('error', function(error) {
        console.error(error.toString());
    })
    .pipe(source("out.js"))
    .pipe(gulp.dest("www"))
})

/* minify with closure */
gulp.task('compile-closure', function () {
    gulp.src('src/**/*.ts')
    .pipe(typescript({target: "es6"}))
    .pipe(gulp.dest("build"))
    .pipe(closureCompiler({
        fileName: "out.js",
        compilerFlags: {
            language_in: "ES6",
            language_out: "ES5",
            compilation_level: "ADVANCED_OPTIMIZATIONS"
        }
    }))
    .pipe(gulp.dest("www"))
    .pipe(size({gzip: true, showFiles: true }))
});

Now I run into three interrelated problems using modules:

So how can I:

Upvotes: 1

Views: 556

Answers (1)

Chad Killingsworth
Chad Killingsworth

Reputation: 14411

This is not yet possible with closure compiler as the compiler does not know how to lookup named modules. The only option would be to use a bundler which can eliminate named module references prior to compilation.

Upvotes: 1

Related Questions