Skip to content

Commit e0204c1

Browse files
committed
Fixes requirejs#349, mention plugins run sync during optimization.
1 parent 4782878 commit e0204c1

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

docs/plugins.html

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ <h2 id="names">
3737

3838
<p>Loader plugins are just another module, but they implement a specific API. Loader plugins can also participate in the optimizer optimizations, allowing the resources they load to be inlined in an optimized build.</p>
3939

40-
<p><b>Note</b>: the plugin and its dependencies should be able to run in non-browser environments like Node and Rhino. If they cannot, you should use an alternate <a href="#apipluginbuilder">plugin builder</a> module that can run in those environments.</p>
40+
<p><b>Note</b>: the plugin and its dependencies should be able to run in non-browser environments like Node and Rhino. If they cannot, you should use an alternate <a href="#apipluginbuilder">plugin builder</a> module that can run in those environments
41+
so that they can participate in optimization builds.</p>
4142

4243
<p>You can reference your plugin by putting its module name before a ! in the dependency. For instance, if you create a plugin with the name "foo.js", you would use it like so:</p>
4344

@@ -153,6 +154,36 @@ <h3>
153154
});
154155
</code></pre>
155156

157+
<p><b id="loadBuildInfo">Build considerations</b>: The optimizer traces
158+
dependencies <b>synchronously</b> to simplify the optimization logic. This is
159+
different from how require.js in the browser works, and it means that only
160+
plugins that can satisfy their dependencies synchronously should participate
161+
in the optimization steps that allow inlining of loader plugin values. Otherwise,
162+
the plugin should just call load() immediately if <code>config.isBuild</code>
163+
is true:</p>
164+
165+
<pre><code>
166+
define({
167+
load: function (name, req, load, config) {
168+
if (config.isBuild) {
169+
//Indicate that the optimizer should not wait
170+
//for this resource any more and complete optimization.
171+
//This resource will be resolved dynamically during
172+
//run time in the web browser.
173+
load();
174+
} else {
175+
//Do something else that can be async.
176+
}
177+
}
178+
});
179+
</code></pre>
180+
181+
<p>Some plugins may do an async operation in the browser, but opt to complete
182+
the resource load synchronously when run in Node/Rhino. This is what the text
183+
plugin does. If you just want to run AMD modules and load plugin
184+
dependencies using <a href="http://github.com/jrburke/amdefine">amdefine</a> in Node, those also need to complete
185+
synchronously to match Node's synchronous module system.</p>
186+
156187
<h3>
157188
<a name="apinormalize">normalize: function (name, normalize)</a>
158189
<span class="sectionMark">&sect; 3.2</span>

0 commit comments

Comments
 (0)