Skip to content

r.js build fails when trying to evaluate a plugin that shouldn't be evaluated #972

Closed
@jslegers

Description

@jslegers

I have an AMD plugin named MapLoader.

When importing samples/template/MapLoader!, this will either return the module luciad/view/Map or the module luciad/view/WebGLMap, depending on the URL query parameter "webgl".

Here's the code of the plugin :

define({
  load: function(na, require, onload, config) {
    if (window.location.search.indexOf('webgl') > 0 && 
        window.location.search.indexOf('webgl=false' < 0)) {
      map = "luciad/view/WebGLMap";
    } else {
      map = "luciad/view/Map";
    }

    require([map], function(value) {
      onload(value);
    });
  }
});

Now, I'm trying to use r.js to pack my project, but it doesn't know how to deal with this module, because it tries to evaluate the code. Hence, it produces the following error :

{ Error: ReferenceError: window is not defined
In module tree:
    samples/balloons/main
      samples/template/sample
        samples/template/MapLoader
  ...
}

My current config looks like this :

require('requirejs').optimize({
  baseUrl : moveFrom,
  modules: [
    { name: "./samples/template/MapLoader" }, 
    { name: "./samples/balloons/main" }
  ],
  packages: [
    { name: "loader", location: "./samples/lib/requirejs" },
    { name: "luciad", location: "./luciad" },
    { name: "samples", location: "./samples" }
  ],
  paths: {
    jquery: "./samples/lib/jquery/jquery-1.12.4"
  },
  dir : moveTo,
  stubModules: ['./samples/template/MapLoader'],
  optimize : "none",
  uglify2 : {
    output: {
      beautify: false
    },
    compress: {},
    warnings: true,
    mangle: true
  }
}, function (buildResponse) {
  console.log(buildResponse);
});

What am I missing?

What is the correct way to add this plugin to my build?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions