How to import part of object in ES6 modules

Unfortunately import statements does not work like object destructuring. Curly braces here mean that you want to import token with this name but not property of default export. Look at this pairs of import/export: //module.js export default ‘A’; export var B = ‘B’; //script.js import A from ‘./a.js’; //import value on default export import {B} … Read more

Typescript compiler error when importing json file

Use var instead of import. var json = require(‘./calls.json’); You’re loading a JSON file, not a module, so import shouldn’t be used is this case. When var is used, require() is treated like a normal function again. If you’re using a Node.js definition, everything should just work, otherwise require will need to be defined.

Webpack and external libraries

According to the Webpack documentation, you can use the externals property on the config object “to specify dependencies for your library that are not resolved by webpack, but become dependencies of the output. This means they are imported from the enviroment while runtime [sic].” The example on that page illustrates it really well, using jQuery. … Read more

Differences between creating a new class to using export const

Would there be a new instance every time I import A? No, modules are only evaluated once. Is one of the benefits of B the ability to use object destructuring and then use method1 as if it existed locally? Yes, though it’s not called “destructuring”. They’re named imports (or named exports of the module), and … Read more

In the `import` syntax of ES6, how is a module evaluated exactly?

When the D module is executed, the console will print this message: A evaluated A constructor Which means that the A module was evaluated only once, even if it was imported multiple times by other modules. The evaluation rules for ES6 modules is the same as for commonjs format: A module is a piece of … Read more

Load “Vanilla” Javascript Libraries into Node.js

Here’s what I think is the ‘rightest’ answer for this situation. Say you have a script file called quadtree.js. You should build a custom node_module that has this sort of directory structure… ./node_modules/quadtree/quadtree-lib/ ./node_modules/quadtree/quadtree-lib/quadtree.js ./node_modules/quadtree/quadtree-lib/README ./node_modules/quadtree/quadtree-lib/some-other-crap.js ./node_modules/quadtree/index.js Everything in your ./node_modules/quadtree/quadtree-lib/ directory are files from your 3rd party library. Then your ./node_modules/quadtree/index.js file will just … Read more