Require.js optimizer does not order dependencies correctly

I have a web application that uses Require to load dependencies. I have a set of JS libraries that are included using the Require object config.shim.

Two such example libraries:

require.config({
  shim: {
    "libs/leaflet": {
        exports: "L"
    }  
    "libs/leaflet-dvf": {
        deps: ["libs/leaflet"],
        exports: "L"
    }
}

The second library leaflet-dvfrequires the first leaflet. The second is a plugin to the first, which depends on the global sphere variable Lthat the first library defines.

When I launch the application using "Require Normal", everything works fine. I can turn on either the library from the strip, and everything works fine. No problems.

, Require r.js Optimizer. , JS , . leaflet-dvf leaflet. JS runtime, L.

:

({
  baseUrl: "../js",
  paths: {
    "requireLib": "../js/libs/require"
  },
  include: ["requireLib"],
  name: "Main",
  out: "bin/Main-built.js",
  optimize: "none",
  wrapShim: true
})

, Rhino, . Main-built.js . L undefined error.

Shims, JS ?

+4
1

, . .

: leafletLib

define(["libs/leaflet","libs/leadleft-dvf"],function(leftlet,dvf){

    return leaflet;
});

LeafletLib . , -dvf , leafletLib. , .

define(["leafletLib"],function(leafletLib){});
+1

Source: https://habr.com/ru/post/1547959/


All Articles