systemjs / builder

SystemJS build tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dependencies not imported directly from the app code not added to the bundle

albv opened this issue · comments

I have something like this in my System.js config file:

System.config({
    map: {
        'angular': 'lib/angular/angular.js',
        'angular-resource': 'lib/angular-resource/angular-resource.js',
        'resource-factory': 'api/resource-factory.js'
    },
    meta: {
        'lib/angular/angular.js': {format: 'global', exports: 'angular'},
        'lib/angular-resource/angular-resource.js': {deps: ['angular']},
        'api/resource-factory.js': {format: 'global', deps: ['angular-resource']}
    }
   ...
});

Then in my application I can write

import 'resource-factory';

and its all working fine in the browser.

But when I build this app with builder.buildSFX() 'angular-resource' module code is not there. I have to explicitly write

import 'angular-resource'; // shouldn't be there
import 'resource-factory';

to make it work.

Are you definitely running the latest version of SystemJS Builder here? Can you confirm if angular-resource is in the list of output.modules provided as the return value of buildSFX?

Builder version is 0.13.3.

import 'angular-resource';
...
output.modules == [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a' ]


// import 'angular-resource';
...
output.modules == [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ]

Global deps builds are definitely working in my tests. Are you sure your meta configuration is applying properly to the resource-factory file? For example to check try changing the format to something like esm to ensure it breaks.

If you can share a test repo that would help a lot as a plain global deps test isn't replicating it for me.

https://github.com/albv/builderjs-test - test repository.

How do I test

  1. npm install && bower install
  2. gulp serve (make sure that angular-resource.js is loaded)
  3. gulp build then look to the dist/app.js file, angular-resource is missing

By the way, when working on this demo I have faced another problem. SystemJS was updated a couple of hours ago to 0.18.4 and my initial setup didn't work with it. I have to add defaultJSExtensions: true option to my builderConfig (see 'scripts:bundle' task in gulpfile.js) because 'app' package settings doesn't apply any more. Could you please take a look at this too?

I was able to fix my last problem by moving package name mapping from 'paths' section to 'map', see albv/builderjs-test@4c9bbad. Still not sure if I am doing it right, this part was working fine with 0.18.3. When I supposed to use 'map' or 'paths' options?
And I have to repeat 'packages' section from my SystemJS config file just to kick off package paths resolution with new mappings (as far as I understand). Is there a better way of doing this?

@albv thanks for posting, I managed to get your build working with albv/builderjs-test#1, and did add a feature in the SystemJS 0.16 release to make this easier in the process (https://github.com/systemjs/systemjs/releases/tag/0.18.16).

@guybedford thank you for the PR, I have merged and tested it, all working as expected (also for my actual project). Still don't exactly know where was my mistake though ) Would you care to elaborate? Anyway I think you can close this issue now. Thanks for your help!

Sure, no problem. Configuration is normalized as it is processed. So the meta config common/... was being normalized to project-folder/common/... instead of project-folder/src/common/... because the config setting common was being applied after the meta config was being applied. With many config calls, the ordering does matter, while with a single call the order is worked out for you.

I thought that separate configs would be merged and when applied at once before build. Now I get it. Thanks!