将require.js源代码与main.js捆绑在一起的方法 [英] Way to bundle require.js source with main.js
问题描述
我有一个独特的情况,我需要在一个文件中同时包含source和main.js,并在该文件中进行所有初始化,因此无需在页面上调用.这可能吗?
I have a unique situation where I need to have both the source and main.js in one file and for everything to initialize within that file, so no require calls on the page. Is this possible?
推荐答案
如果要在main.js源代码中包含require.js,可以使用以下命令:
If you want to include require.js with the main.js source, you can use this kind of command:
node ../../r.js -o baseUrl=. paths.requireLib=../../require name=main include=requireLib out=main-built.js
由于"require"是保留的依赖项名称,因此您将创建" requireLib "依赖项并将其映射到require.js文件.
Since "require" is a reserved dependency name, you create a "requireLib" dependency and map it to the require.js file.
优化完成后,您可以将脚本标签更改为引用"main-built.js"而不是"require.js",并且您优化的项目仅需要发出一个脚本请求.
Once that optimization is done, you can change the script tag to reference "main-built.js" instead of "require.js", and your optimized project will only need to make one script request.
这篇关于将require.js源代码与main.js捆绑在一起的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!