Export external JavaScript librariesExport external JavaScript librarieshttps://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=1216286592024-03-29T01:25:30Z2024-03-29T01:25:30ZRE: Export external JavaScript librariesOlaf Kockhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1216300932023-01-17T12:32:39Z2023-01-17T12:32:38Z<p>As you're in a portlet, you can set
<code>com.liferay.portlet.footer-portal-javascript</code> or
<code>com.liferay.portlet.header-portal-javascript</code> in the
<code>@Component</code>'s properties (or in portlet.xml - <a
href="https://help.liferay.com/hc/en-us/articles/360017901292-Portlet-Descriptor-to-OSGi-Service-Property-Map">check
this mapping</a>)</p>Olaf Kock2023-01-17T12:32:38ZExport external JavaScript librariesSébastien Bhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1216286582023-01-13T12:13:13Z2023-01-13T12:11:59Z<p>Hello, <br />
<br /> I would like to export some javascript functions from a module
to use it in portlet. In 7.1 version, it wad possible do
"addModule" as an AMD module and to use it in portlet by
"require" aui for example. <br />
<br /> I am currently upgrading my portatl in 7.4 and
"addModule" does not exist anymore :</p>
<p>Previously, in my config.js and my-library.js :</p>
<pre>
<code class="language-javascript">Liferay.Loader.addModule({
dependencies: [],
name: 'jquery',
anonymous: true,
path: MODULE_PATH + 'my-library.js'
});</code></pre>
<pre>
<code class="language-java">// Assuming your "module" will be exported as "my-library"
(function (root, factory) {
if (typeof Liferay.Loader.define === 'function' && Liferay.Loader.define.amd) {
// AMD. Register as a "named" module.
Liferay.Loader.define('my-library', [], factory);
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root['my-library] = factory();
}
}(this, function () {
myFunction= function () {
console.log('call my function');
}
}));
</code></pre>
<p> </p>
<p>Now, i've tried to do it with liferay-npm-bundler but i've not
succeeded to expose my library with this method. If someone as already
done a similar modu