Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过 data-main 引入的文件,可能不会出现在 html_map.js 文件中 #41

Open
ystarlongzi opened this issue Feb 23, 2016 · 2 comments

Comments

@ystarlongzi
Copy link

假设有以下目录,其中目录中的 .es6 文件,会被编译成 .js 文件输出。

-- page
    -- index.html
    -- bootstrap.es6
    -- main.js
    -- main1.es6
    -- require.js

main.jsmain1.es6 文件内容相同,如下:

require(['index.js'], function () {});

分别通过以下几个场景在 index.html 引入 require.js 文件

<!-- 场景1 -->
<script data-main="main.js" src="require.js"></script>

<!-- 场景2 -->
<script data-main="main1.es6" src="require.js"></script>

<!-- 场景3 -->
<!-- 
    注意:
    __uri() 是使用了 fis3-parser-html-uri 插件,增强 fis 的资源定位能力。
    在 fis 的 `parser` 阶段,它会将 __uri(main.es6) 替换成 /page/index/main1.js
-->
<script data-main="__uri(main1.es6)" src="require.js"></script>

在上面的三个场景中:

  1. 场景1是正常的,data-main 会被替换为正确的地址,也会生成 index_html_map.js 配置文件
  2. 场景2,由于 data-main="/page/index/main1.es6",导致无法加载入口文件,但也算『符合预期』。它也会生成index_html_map.js 配置文件
  3. 场景3,无法生成 index_html_map.js 配置文件,但其实发布后是存在 /page/index/main1.js 文件的。

那么在 场景3下,无法生成 index_html_map.js 文件,是因为在产出前不存在 /page/index/main1.js 造成的嘛?

@2betop
Copy link
Contributor

2betop commented Feb 23, 2016

场景3就不考虑了,原因如你所说。

场景2居然不正确?那个 data-main 应该是产出 module Id 还是 module path? 你手动改成 module path 就正确了?

@ystarlongzi
Copy link
Author

场景2下生成的配置文件如下:

require.config({paths:{
    "page/index/index.es6": "/page/index/index",
    "page/index/main1.es6": "/page/index/main1"
}});

而实际加载 main1.es6 文件的路径却是 /page/index/mina1.es6.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants