search

Home  >  Q&A  >  body text

javascript - es6 require parameter problem

I haven’t found much specific usage of es6 require. Most of them are briefly introduced to load modules, such as
const es_namespace = require('./es');
But I have seen this use of resolve elsewhere. => require(['../pages/login/'], resolve), what does this require function mean? Is there any official documentation? Or go into details?

phpcn_u1582phpcn_u15822858 days ago786

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-05-19 10:41:44

    ES6 modularization uses import and export. For details, you can see "Understanding ECMAScript6" https://sagittarius-rev.gitbo...,
    Chapter 13 of this book uses modules to encapsulate code. I think it is very well written. , very clear and concise.

    The require you are talking about is a js library RequireJS,
    Chinese document http://www.requirejs.cn/,
    This tutorial is also good http://www.runoob.com/w3cnote...

    reply
    0
  • ringa_lee

    ringa_lee2017-05-19 10:41:44

    Because requirerequire.js is a library, you can take a look at Ruan Yifeng’s introduction on how to use require.js

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-19 10:41:44

    当 Node 遇到 require(X) 时,按下面的顺序处理。
    (1)如果 X 是内置模块(比如 require('http')) 
      a. 返回该模块。 
      b. 不再继续执行。
    (2)如果 X 以 "./" 或者 "/" 或者 "../" 开头 
      a. 根据 X 所在的父模块,确定 X 的绝对路径。 
      b. 将 X 当成文件,依次查找下面文件,只要其中有一个存在,就返回该文件,不再继续执行。
    X
    X.js
    X.json
    X.node
      c. 将 X 当成目录,依次查找下面文件,只要其中有一个存在,就返回该文件,不再继续执行。
    X/package.json(main字段)
    X/index.js
    X/index.json
    X/index.node
    (3)如果 X 不带路径 
      a. 根据 X 所在的父模块,确定 X 可能的安装目录。 
      b. 依次在每个目录中,将 X 当成文件名或目录名加载。
    (4) 抛出 "not found"

    This is how require works.
    ['../pages/login/'] may load all files under "../pages/login/"
    You can refer to require() source code interpretation

    reply
    0
  • Cancelreply