es6-modules

ES6 javascript import external js file

旧巷老猫 提交于 2019-12-01 01:52:21
I'm trying this in my ES6 javascript module: import externalutil from 'https://externalutil.com/js/externalutil.js'; but it fails with this transpile error: Module not found: 'https://externalutil.com/js/externalutil.js' The file externalutil.js is an old-fashioned javascript library that does not export anything. Any help will be appreciated. Joseph Callaars You cannot import URL's (as of yet). You should download the file, put it somewhere locally and reference it locally as well. However in your case, I'd just use a <script /> tag to include it in your html and just access the window object

How does jest allow mutation of modules?

丶灬走出姿态 提交于 2019-12-01 01:50:01
问题 In this question that I asked here: Why does mutating a module update the reference if calling that module from another module, but not if calling from itself? I'm asking about the nature of module mutation. However as it it turns out, ES6 modules can't actually be mutated - all of their properties are treated as constants. (See this answer) But somehow - when Jest tests modules - they can be mutated, and that's how Jest allows for mocking. How is this happening? I imagine that it's a babel

Find value in javascript array of objects deeply nested with ES6

北战南征 提交于 2019-12-01 01:12:58
问题 In an array of objects I need to find a value -- where key is activity : However the activity key can be deeply nested in the array like so: const activityItems = [ { name: 'Sunday', items: [ { name: 'Gym', activity: 'weights', }, ], }, { name: 'Monday', items: [ { name: 'Track', activity: 'race', }, { name: 'Work', activity: 'meeting', }, { name: 'Swim', items: [ { name: 'Beach', activity: 'scuba diving', }, { name: 'Pool', activity: 'back stroke', }, ], }, ], }, {} ... {} ... ]; So I wrote

es6 Import of three.js

房东的猫 提交于 2019-11-30 19:17:41
My workflow for es6 uses babel and babel-plugin-transform-es2015-modules-system.js to only transform module import/export for use with system.js. I simply use a "green" browser for all es6 features except import/export of modules .. which are a whatwg standard thus not "es6". This works with legacy (non-es6) libraries well, I can "import" all the npm packages I need. Somehow babel, with only the babel modules transform, and system.js magically work. Except for three.js. I tried it with all three releases: three.js, three.min.js & three.modules.js. The first two fail silently, resulting in a

Can I use ES6 modules in Node.js 8? [duplicate]

为君一笑 提交于 2019-11-30 17:41:38
This question already has an answer here: NodeJS plans to support import/export es6 (es2015) modules 1 answer Can I use ES6 module syntax with Node.js starting from version 8? Similar questions have already been asked on this site, but answers there are obsolete. I wonder if the situation has changed with new version of Node.js? https://medium.com/the-node-js-collection/an-update-on-es6-modules-in-node-js-42c958b890c It is in progress but the ETA is 2018 at the earliest. 来源: https://stackoverflow.com/questions/45379888/can-i-use-es6-modules-in-node-js-8

Output an ES module using webpack

て烟熏妆下的殇ゞ 提交于 2019-11-30 12:38:09
问题 With Rollup I can output an ES module by simply setting the format option to 'es' . How can I do the same with webpack? If it's not possible now, does webpack have any plans to add it? The only thing I've found in the documentation for output.libraryTarget that mentions ES modules is this: libraryTarget: "commonjs-module" - Expose it using the module.exports object ( output.library is ignored), __esModule is defined (it's threaded as ES2015 Module in interop mode) However, it's rather unclear

es6 Import of three.js

大城市里の小女人 提交于 2019-11-30 03:31:13
问题 My workflow for es6 uses babel and babel-plugin-transform-es2015-modules-system.js to only transform module import/export for use with system.js. I simply use a "green" browser for all es6 features except import/export of modules .. which are a whatwg standard thus not "es6". This works with legacy (non-es6) libraries well, I can "import" all the npm packages I need. Somehow babel, with only the babel modules transform, and system.js magically work. Except for three.js. I tried it with all

Test ES6 modules with Jest

旧街凉风 提交于 2019-11-29 12:44:37
How to test ES6 modules with Jest. Example: sum.js const sum = function (a, b) { return a + b; } export default sum; sum.test.js import sum from './sum'; test('adds 1 + 2 to equal 3', () => { expect(sum(1, 2)).toBe(3); }); The only requirement is to config your test environment to Babel, and add the es2015 transform plugin: Step 1: Add your test environment to .babelrc in the root of your project: { "env": { "test": { "plugins": ["transform-es2015-modules-commonjs"] } } } Step 2: Install the es2015 transform plugin: npm install --save-dev babel-plugin-transform-es2015-modules-commonjs And that

How to import es6 module that has been defined in <script type=“module”> tag inside html?

怎甘沉沦 提交于 2019-11-29 10:55:32
I am able to define a module in my html file me.html: <script type="module" id="DEFAULT_MODULE"> import Atom from './atom.js'; console.log("definition of getAtom") export default function getAtom(){ return new Atom('atom'); } console.log("exported getAtom") </script> Also see https://blog.whatwg.org/js-modules https://github.com/whatwg/html/pull/443#issuecomment-167639239 => Is it possible to import that "anonymous" module to another module script in the same html file? Or to some "code behind"- JavaScript file that also has been loaded by the me.html file? The export seems to work; at least

Javascript reference vs binding…what's the difference?

我的梦境 提交于 2019-11-29 06:15:36
I recently read the following in Kyle Simpson's You Don't Know JS: ES6 "[ES6 modules export] actual bindings (almost like pointers) to the identifiers in your inner module definition." My confusion is how these bindings differ from references... I understand that a reference in JS is only applicable to non-primitive types (like objects), so that given let object1 = {a: 1}; let object2 = object1; object1 and object2 now refer to (they are both references to) the same object. If I add a property to object2 , I am also adding a property to object1 object2.b = 2; console.log(object1.b); // 2 And I