Can I use an ES6/2015 module import to set a reference in ‘global’ scope?

Shimming modules is the way to go: http://webpack.github.io/docs/shimming-modules.html I quote from the page: plugin ProvidePlugin This plugin makes a module available as variable in every module. The module is required only if you use the variable. Example: Make $ and jQuery available in every module without writing require(“jquery”). new webpack.ProvidePlugin({ $: “jquery”, jQuery: “jquery”, “window.jQuery”: … Read more

How to correctly use ES6 “export default” with CommonJS “require”?

To use export default with Babel, you can do 1 of the following: require(“myStuff”).default npm install babel-plugin-add-module-exports –save-dev Or 3: //myStuff.js var thingToExport = {}; Object.defineProperty(exports, “__esModule”, { value: true }); exports[“default”] = thingToExport;

How do I extend another VueJS component in a single-file component? (ES6 vue-loader)

After some testing, the simple solution was to be sure to export a Vue.extend() object rather than a plain object for any component being extended. In my case, the base component: import Vue from ‘vue’ export default Vue.extend({ [component “Foo” definition] }) and the extended component: import Foo from ‘./Foo’ export default Foo.extend({ [extended component … Read more

How to import everything exported from a file with ES2015 syntax? Is there a wildcard?

You cannot import all variables by wildcard for the first variant because it causes clashing variables if you have it with the same name in different files. //a.js export const MY_VAR = 1; //b.js export const MY_VAR = 2; //index.js import * from ‘./a.js’; import * from ‘./b.js’; console.log(MY_VAR); // which value should be there? … Read more

What is the defined execution order of ES6 imports?

JavaScript modules are evaluated asynchronously. However, all imports are evaluated prior to the body of module doing the importing. This makes JavaScript modules different from CommonJS modules in Node or <script> tags without the async attribute. JavaScript modules are closer to the AMD spec when it comes to how they are loaded. For more detail, … Read more

How to fix this ES6 module circular dependency?

The answer is to use “init functions”. For reference, look at the two messages starting here: https://esdiscuss.org/topic/how-to-solve-this-basic-es6-module-circular-dependency-problem#content-21 The solution looks like this: // — Module A import C, {initC} from ‘./c’; initC(); console.log(‘Module A’, C) class A extends C { // … } export {A as default} – // — Module B import C, {initC} … Read more