Frank van Luijn
Frank van Luijn

Reputation: 470

jspm not loading bundles with --inject

Been experimenting with jspm and systemjs over the weekend. Everything is working fine except for the bundling jspm offers. I can load individual files, but jsmp refuses to load the bundle file (which is optimized).

I'm creating the bundle file using:

jspm bundle lib/login assets/js/1-login.js --inject

This updates the config.js file which looks like:

System.config({
    baseURL: "/",
    defaultJSExtensions: true,
    transpiler: "babel",
    babelOptions: {
        "optional": [
            "optimisation.modules.system"
        ]
    },
    paths: {
         "github:*": "jspm_packages/github/*",
         "npm:*": "jspm_packages/npm/*"
    },
    bundles: {
         "1-login.js": [
             "lib/login.js",
             "lib/sample.js"
         ]
    },
    map: {....}
});

lib/login.js

import * as sample from 'lib/sample'

export function test() {
    sample.testMethod();
}

lib/sample.js

import $ from 'jquery'

export function testMethod( ) {
    console.log( $('body') );
}

So, according to the jsmp docs:

As soon as one of these modules is requested, the request is intercepted and the bundle is loaded dynamically first, before continuing with the module load.

It's my understanding that running

System.import('lib/login.js');

should load the bundle (and optimised file), but is doesn't - it just loads the actual file. What am I missing here? And as a bonus question, why is jquery not in the bundle list?

Upvotes: 1

Views: 696

Answers (1)

Frank van Luijn
Frank van Luijn

Reputation: 470

Well, figured out where I went wrong. I keep all the generated assets in assets/js, but in my config.json I didn't change the baseUrl to reflect this. I did in fact have the baseUrl set correctly in package.json, which is why jspm didn't throw a lot of errors. This was the same reason jquery wasn't loading, so problem solved :)

Upvotes: 1

Related Questions