systemjs / builder

SystemJS build tool
MIT License
466 stars 122 forks source link

Build using existing System.register bundles #838

Open matthewjh opened 6 years ago

matthewjh commented 6 years ago

Hello,

I have an existing System.js bundle (that is, a single file containing many System.register calls) that is produced by the TypeScript compiler with module="System". What I want to do is build some new bundles from subtrees of the modules represented in this file. For example, say my TS-generated bundle file contains modules A, B, and C. I want to use the System.js builder to build new two bundles using A and B respectively as entry points.

I tried to do this using the "bundles" config property without any luck:

var path = require("path");
var Builder = require('systemjs-builder');

function build () {
    var builder = new Builder(
        undefined,
        "build/renderer-system-config.js"
    );
    builder.bundle("renderer/index", "out-lol.js")
        .then(() => {
            console.log("build success");
        })
        .catch(e => {
            console.error(e);
        });
}

build(); 

renderer-system-config.js

SystemJS.config({
    baseURL: "src",
    bundles: {
        "renderer/out.js": ["renderer/index"]
    }
});

renderer/out.js contains

System.register("renderer/index", .... );

and a bunch of other System.register'd modules.

My expectation was that thanks to the "bundle" property in my config, when I call builder.bundle("renderer/index", ...), System.js would go and fetch renderer/out.js. This seems not to be the case:

 Error on fetch for renderer/index at file:///D:/a/b/src/renderer/index
        Error: ENOENT: no such file or directory, open 'D:\a\b\src\renderer\index'
    at Error (native)
  originalErr:
   { Error: ENOENT: no such file or directory, open 'D:\a\b\src\renderer\index'
       at Error (native)
     errno: -4058,
     code: 'ENOENT',
     syscall: 'open',
     path: 'D:\\a\\b\\src\\renderer\\index' } }

Does anyone know the right way to approach this?