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 stop babel from transpiling ‘this’ to ‘undefined’ (and inserting “use strict”)

For Babel >= 7.x ES6 code has two processing modes: “script” – When you load a file via a <script>, or any other standard ES5 way of loading a file “module” – When a file is processed as an ES6 module In Babel 7.x, files are parsed as “module” by default. The thing that is … 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