amdjs 2.0.3 copy "amdjs: ^2.0.3" to clipboard
amdjs: ^2.0.3 copied to clipboard

Platformweb

JavaScript AMD (Asynchronous Module Definition) Dart interoperability.

AMDJS #

pub package Null Safety

CI GitHub Tag New Commits Last Commits Pull Requests Code size License

JavaScript AMD (Asynchronous Module Definition) Dart interoperability.

When using JS libraries that uses AMD (RequireJS), you need to call the JS function require() to correctly load the library or unpredicted behaviors will happens.

This Dart packages helps to transparently load JS libraries from Dart, using native AMD require(), when present, or just adding a <script src="library.js"></script> into DOM.

Usage #

A simple usage example:

import 'package:amdjs/amdjs.dart';

// Running on browser:
main() async {
 
  // Check if AMD is already loaded in JS context (usually when RequireJS is already loaded in DOM):
  var inNativeMode = AMDJS.isNativeImplementationPresent() ;
 
  // Load JQuery:
  var okJQuery = await AMDJS.require('jquery', '/js/jsquey.js' , globalJSVariableName: 'jquery') ;
 
  // Bootstrap recommends to add script tag inside body. The parameter `addScriptTagInsideBody` will be
  // used only when mimicking AMD, and ignored when running in native mode:
  var okBootstrap = await AMDJS.require('bootstrap', '/js/bootstrap.js', addScriptTagInsideBody: true) ;
  
  if (okJQuery && okBootstrap) {
    print('Bootstrap correctly loaded (JQuery 1st, Bootstrap 2nd).');
  }


}

Common issues loading JS libraries with Dart #

Since Dart, specially in development mode, uses AMD (RequireJS or similar) to load its packages, any other JS library inserted using <script src"library-x.js""></script> won't load correctly. This package (amdjs) helps to identify that and correctly load libraries.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Author #

Graciliano M. Passos: gmpassos@GitHub.

License #

Dart free & open-source license.

7
likes
160
pub points
47%
popularity

Publisher

unverified uploader

JavaScript AMD (Asynchronous Module Definition) Dart interoperability.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

dom_tools, swiss_knife

More

Packages that depend on amdjs