How to import ES6 modules in content script for Chrome Extension

As it’s already mentioned, for background script, it’s good idea to use background.page and use <script type=”module”> to kick your JavaScript. The problem is content script, and injecting <script> tag with type attribute can be a solution. Another approach than injecting script tag is to use dynamic import function. By this approach, you don’t need … Read more

import * as React from ‘react’; vs import React from ‘react’;

TL;DR Indeed ES import statements import default and import * are not the same thing, the fact that they behave the same in this case is a combination of how React authors chose to publish the library and compatibility layers in TypeScript (using esModuleInterop) or Babel and your bundler to make them “just work”. It … Read more

Why are Objects not Iterable in JavaScript?

I’ll give this a try. Note that I’m not affiliated with ECMA and have no visibility into their decision-making process, so I cannot definitively say why they have or have not done anything. However, I’ll state my assumptions and take my best shot. 1. Why add a for…of construct in the first place? JavaScript already … Read more

Do I need require js when I use babel?

Do I need require js when I use babel? You might need some module loader, but it is not necessary RequireJS. You have several options. The following will help you to get started. rollup.js with rollup-plugin-babel Rollup is a next-generation JavaScript module bundler. It understands ES2015 modules natively, and will produce a bundle that doesn’t … Read more

Arrow function without curly braces

The parenthesis are returning a single value, the curly braces are executing multiple lines of code. Your example looks confusing because it’s using JSX which looks like multiple “lines” but really just gets compiled to a single “element.” Here are some more examples that all do the same thing: const a = (who) => “hello … Read more