es6-modules

How can we use es6 modules in modern web browsers without transpiling the code

风格不统一 提交于 2019-12-02 12:01:52
问题 Is it possible to use es6 module system and import modules in web browsers? 回答1: With chrome 61, es6 module system is introduced to the world of web browsers. This link https://developers.google.com/web/fundamentals/primers/modules can be referred for more details on how chrome implements the module system. Some of the important features of es6 module system discussed in the above link are: Modules by default are strict mode. They are not lexical top-level scope, which is var foo = 42 in

Re-exporting modules does not work with object spread

蓝咒 提交于 2019-12-02 06:24:51
问题 i have an index.js file that reads: import aReducer from './ducks/a'; import bReducer from './ducks/b'; import * as aSelectors from './ducks/a'; import * as bSelectors from './ducks/b'; console.log(aReducer) //function i expect console.log(aSelectors) //object with keys to selectors i expect export { aReducer, bReducer, ...aSelectors, ...bSelectors }; If I console.log in this file I see that the reducers are functions I expect and the selectors alias are objects with keys to the selectors I

ES6 how to export all item from one file

随声附和 提交于 2019-12-02 04:20:02
问题 I want to export all methods of a file from another file. currently I am doing this, and it works. How can I merge below two into 1 export expression import * as db from './web/query'; export default db; I tried below written 1 line exports but all failed export * from './web/query'; //==error export * as default from './web/query'; //==error export * as {default} from './web/query'; //==error export from from './web/query'; //== error export default from './web/query'; //== error Error means

Re-exporting modules does not work with object spread

给你一囗甜甜゛ 提交于 2019-12-02 03:10:12
i have an index.js file that reads: import aReducer from './ducks/a'; import bReducer from './ducks/b'; import * as aSelectors from './ducks/a'; import * as bSelectors from './ducks/b'; console.log(aReducer) //function i expect console.log(aSelectors) //object with keys to selectors i expect export { aReducer, bReducer, ...aSelectors, ...bSelectors }; If I console.log in this file I see that the reducers are functions I expect and the selectors alias are objects with keys to the selectors I expect. The reducers are default exports for the duck files and the selectors are exports from the same

How can we use es6 modules in modern web browsers without transpiling the code

戏子无情 提交于 2019-12-02 02:59:48
Is it possible to use es6 module system and import modules in web browsers? With chrome 61, es6 module system is introduced to the world of web browsers. This link https://developers.google.com/web/fundamentals/primers/modules can be referred for more details on how chrome implements the module system. Some of the important features of es6 module system discussed in the above link are: Modules by default are strict mode. They are not lexical top-level scope, which is var foo = 42 in module file won't be available as window.foo. Modules are included in html file as <script type="module" src=

ES6 Modules: Exporting and importing performance differences

佐手、 提交于 2019-12-01 17:49:07
I have some components in my vue project. I don't like import loader from '@/components/someComponent1/someComponent1.vue'; because it's a lot to write and I have to repeat it for every component. So I wrote an index.js for the components folder: export { default as someComponent1 } from './someComponent1/someComponent1.vue'; export { default as someComponent2 } from './someComponent2/someComponent2.vue'; ... This will allow me to import multiple components in one line: import { someComponent1, someComponent2 } from '@/components'; My question: Is it possible that the index.js -ish-way is

ES6 Modules: Exporting and importing performance differences

浪尽此生 提交于 2019-12-01 16:09:46
问题 I have some components in my vue project. I don't like import loader from '@/components/someComponent1/someComponent1.vue'; because it's a lot to write and I have to repeat it for every component. So I wrote an index.js for the components folder: export { default as someComponent1 } from './someComponent1/someComponent1.vue'; export { default as someComponent2 } from './someComponent2/someComponent2.vue'; ... This will allow me to import multiple components in one line: import {

How to use ES6 modules from dev tools console

流过昼夜 提交于 2019-12-01 14:16:41
问题 As far as I understand it, if I create an ES6 module, I can only import it from code that is itself a module. This means non-module code, i.e. inline Javascript, or the Chrome dev tools console can never access code that is in a module. Is that true? Is there any way around this because it seems like a fairly extreme limitation. 回答1: You can use dynamic import within Chrome's console. import('path/to/module.js').then(m => module = m) // [doSomething] is an exported function from [module.js].

How to dynamically execute/eval JavaScript code that contains an ES6 module / requires some dependencies?

时光毁灭记忆、已成空白 提交于 2019-12-01 05:14:38
I want my users to be able to use JavaScript as a scripting language inside my JavaScript application. In order to do so, I need to dynamically execute the source code. There seem to be two main options for dynamically executing JavaScript: a) Use eval(...) method ( or var func = new Function(...); ) . b) Add a <script> node to the DOM (for example by using $('body').append(...) ). Both methods work fine as long as I do not use any import statements in the dynamically executed source code. If I include import statements I get the error message Unexpected identifier . Example user source code

How does jest allow mutation of modules?

元气小坏坏 提交于 2019-12-01 04:12:21
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 plugin that that's running - transpiling the module to CommonJS modules? Is there any documentation