You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/plugins.html
+32-1Lines changed: 32 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,8 @@ <h2 id="names">
37
37
38
38
<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>
39
39
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 <ahref="#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 <ahref="#apipluginbuilder">plugin builder</a> module that can run in those environments
41
+
so that they can participate in optimization builds.</p>
41
42
42
43
<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>
43
44
@@ -153,6 +154,36 @@ <h3>
153
154
});
154
155
</code></pre>
155
156
157
+
<p><bid="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 <ahref="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
+
156
187
<h3>
157
188
<aname="apinormalize">normalize: function (name, normalize)</a>
0 commit comments