Webpack ProvidePlugin vs externals?

It’s both possible: You can include libraries with a <script> (i. e. to use a library from a CDN) or include them into the generated bundle. If you load it via <script> tag, you can use the externals option to allow to write require(…) in your modules. Example with library from CDN: <script src=”https://code.jquery.com/jquery-git2.min.js”></script> // … Read more

Requirejs why and when to use shim config

A primary use of shim is with libraries that don’t support AMD, but you need to manage their dependencies. For example, in the Backbone and Underscore example above: you know that Backbone requires Underscore, so suppose you wrote your code like this: require([‘underscore’, ‘backbone’] , function( Underscore, Backbone ) { // do something with Backbone … Read more

How to disable the warning ‘define’ is not defined using JSHint and RequireJS

Just to expand a bit, here’s a .jshintrc setup for Mocha: { …. “globals” : { /* MOCHA */ “describe” : false, “it” : false, “before” : false, “beforeEach” : false, “after” : false, “afterEach” : false } } From the JSHint Docs – the false (the default) means the variable is read-only. If you … Read more

Relation between CommonJS, AMD and RequireJS?

RequireJS implements the AMD API (source). CommonJS is a way of defining modules with the help of an exports object, that defines the module contents. Simply put, a CommonJS implementation might work like this: // someModule.js exports.doSomething = function() { return “foo”; }; //otherModule.js var someModule = require(‘someModule’); // in the vein of node exports.doSomethingElse … Read more