Search code examples
node.jsgulpsystemjsjspm

System.js builder.buildStatic just outputs the filename


I have just simplified the source file to below, which works fine when I use System.import in a script tag.

import angular from "angular";

angular.element(document).ready(function () {
    alert('Hello word');;
});

Below is my config.js

System.config({
  baseURL: "/",
  defaultJSExtensions: true,
  transpiler: "typescript",
  paths: {
    "npm:": "jspm_packages/npm/"
  },

  map: {
    "angular": "npm:angular@1.5.2",
    "typescript": "npm:typescript@1.8.9"
  }
});

I have a gulp task to build it:

gulp.task('bundle:js', ['clean:js'], function () {

    var builder = new Builder();
    builder.loadConfig('./config.js').then(function () {
        var destination = paths.coreJsDest;
        builder.buildStatic(paths.srcRoot + 'js/ng/homepage', destination, {
            minify: false,
            sourceMaps: false,
           runtime: false
        });
    });
});

But the output file contains the file name rather than JavaScript from the file and its imports:

(["1"], ["1"], function($__System) {

})
(function(factory) {
  if (typeof define == 'function' && define.amd)
    define(["D:/Projects/etc-etc/assets/js/ng/homepage.js"], factory);
  else if (typeof module == 'object' && module.exports && typeof require == 'function')
    module.exports = factory(require("D:/Projects/etc-etc/js/ng/homepage.js"));
  else
    throw new Error("Module must be loaded as AMD or CommonJS");
});

Solution

  • Doh, I just needed to change the baseUrl from "/" to "./".