Giter Club home page Giter Club logo

Comments (5)

errorrik avatar errorrik commented on August 24, 2024

我觉得你对data-main的理解稍微有点问题。

main指的是入口模块,用于app启动的。类似于C里的main函数。通常情况下一个应用总需要一个模块作为启动入口,data-main正是为此诞生。

正确使用data-main的姿势是:

<head>
<script data-main="main" src="js/require.js"></script>
</head>

假设你要配置config,正确姿势应该是:

<head>
<script data-main="main" src="js/require.js"></script>
<script>
require.config({
});
</script>
</head>

不正确的姿势是:

html:
-----------
<head>
<script data-main="js/config" src="js/require.js"></script>
</head>

js/config.js:
-----------
require.config({});
require(['main'], function (main) {
});

from esl.

Yunhui avatar Yunhui commented on August 24, 2024

确实是这样,但是随便举个例子而已。如果有data-main的话,我可以减少写一行入口模块的执行脚本

from esl.

errorrik avatar errorrik commented on August 24, 2024

了解,有空的时候我实现下,看看体积具体增加了多少,再决定是否加入此特性。此issue先保持open状态

from esl.

Yunhui avatar Yunhui commented on August 24, 2024

其实很早之前用require.js的第一思路是。

<script data-main="js/config" src="js/require.js"></script>

```javascript
// config.js
require.config({
    paths: {
        jquery:"lib/jquery.min"
    }
});

```javascript
// 当前页面的js
require(['jquery'], function($){
    console.log($)
});

然后直接就挂了。

from esl.

errorrik avatar errorrik commented on August 24, 2024

挂是对的。因为页面上js执行时,你config.js还没回来,所以require(['jquery']压根就没法去正确的位置请求

from esl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.