Answer 1: If you write import React from 'react';, webpack will give priority to see if you have defined resolve.alias. code>react, if not, look for it in node_modules. import React from 'react';,webpack会优先看看你有没有在resolve.alias里看看你有没有定义react,如果没有的话,就在node_modules里找。
Answer 2: Both import and export are ES6 syntax and are not built-in objects. You see, webpack1 does not support this import/export syntax. You need to use babel to convert it to commonjs writing require . 🎜
Question 1: It is determined by the module loading mechanism of nodejs. You can read the official documentation. If you are not familiar with NODE, there is nothing you can do. Question 2: There is no conflict between the built-in objects of ES6 and NODE. Node relies on the V8 platform, so whether ES6 syntax is supported or not depends on the V8 platform, and V8 currently partially supports ES6. However, since react needs to run on the browser side, in order to ensure browser compatibility, babel is generally required to translate it into standard ES5 syntax. This actually has nothing to do with node itself, but to be compatible with different versions of browsers. .
Answer 1: If you write
import React from 'react';
, webpack will give priority to see if you have definedresolve.alias
. code>react, if not, look for it innode_modules
.import React from 'react';
,webpack会优先看看你有没有在resolve.alias
里看看你有没有定义react
,如果没有的话,就在node_modules
里找。答问二:这import和export都是ES6的语法,并不是什么内置对象,你看webpack1就不支持这import/export的语法,需要用babel转换成commonjs的写法
Answer 2: Both import and export are ES6 syntax and are not built-in objects. You see, webpack1 does not support this import/export syntax. You need to use babel to convert it to commonjs writingrequire
require
. 🎜Question 1: It is determined by the module loading mechanism of nodejs. You can read the official documentation. If you are not familiar with NODE, there is nothing you can do.
Question 2: There is no conflict between the built-in objects of ES6 and NODE. Node relies on the V8 platform, so whether ES6 syntax is supported or not depends on the V8 platform, and V8 currently partially supports ES6.
However, since react needs to run on the browser side, in order to ensure browser compatibility, babel is generally required to translate it into standard ES5 syntax. This actually has nothing to do with node itself, but to be compatible with different versions of browsers. .