<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Use npm scripts with AMD Module Loader in the frontend, e.g. webcontent</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=111990200" />
  <subtitle>Use npm scripts with AMD Module Loader in the frontend, e.g. webcontent</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=111990200</id>
  <updated>2026-04-05T10:04:50Z</updated>
  <dc:date>2026-04-05T10:04:50Z</dc:date>
  <entry>
    <title>RE: Use npm scripts with AMD Module Loader in the frontend, e.g. webcontent</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112935438" />
    <author>
      <name>Severin Rohner</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112935438</id>
    <updated>2019-03-29T10:25:39Z</updated>
    <published>2019-03-29T10:25:39Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hi Ivan&lt;br&gt;&lt;br&gt;Thanks for your answer and sorry for my late response.&lt;br&gt;&lt;br&gt;It works great with the new module loader. &lt;br&gt;&lt;br&gt;I just added the dependency in the package.json:&lt;pre&gt;&lt;code&gt;{
  "dependencies": {
    "bricks.js": "1.8.0"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "liferay-npm-bundler": "^2.0.0"
  },
  "scripts": {
    "build": "babel --source-maps -d build/resources/main/META-INF/resources src/main/resources/META-INF/resources &amp;amp;amp;&amp;amp;amp; liferay-npm-bundler"
  },
  "main": "index.es.js",
  "name": "dep-bricks",
  "version": "1.8.0"
}
&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt; and export the bricks.js in the index.es.js:&lt;pre&gt;&lt;code&gt;import Bricks from 'bricks.js'

export default Bricks&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;​​​​​​​&lt;br&gt;In the frontend (e.g. Freemarker template) it can be used in this way&lt;pre&gt;&lt;code&gt;&amp;lt;script type="text/javascript"&amp;gt;

  Liferay.Loader.require('dep-bricks@1.8.0/index.es', function(module) {
        var Bricks = module.default;

        var sizes = [
            { columns: 1, gutter: 0 },
            { mq: '1280px', columns: 3, gutter: 22 }
        ];

        var bricksInstance = Bricks({
            container: '.container',
            packed:    'data-packed',
            sizes:     sizes
        });

        AUI().ready(function(){&amp;nbsp;
          bricksInstance.pack();
        });

        window.addEventListener('resize', function(){
            bricksInstance.pack();
        }, true);

    }, function(error) {
        console.error(error);
    });

&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;Cheers Severin&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Severin Rohner</dc:creator>
    <dc:date>2019-03-29T10:25:39Z</dc:date>
  </entry>
  <entry>
    <title>RE: Use npm scripts with AMD Module Loader in the frontend, e.g. webcontent</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111999552" />
    <author>
      <name>Iván Zaera Avellón</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111999552</id>
    <updated>2019-01-14T08:02:46Z</updated>
    <published>2019-01-14T08:02:46Z</published>
    <summary type="html">&lt;p&gt;Hi Severin:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;You can leave it as it is, it should work. However, the config
  generator is deprecated in favor of the new npm bundler. You can see
  the docs for the new tool here -&amp;gt;
  https://github.com/liferay/liferay-npm-build-tools/wiki and here -&amp;gt; https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/using-npm-in-your-portlets&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Please carefully read the documentation until you understand the new
  model and feel free to ask any doubt you may have here.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Ivan&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Iván Zaera Avellón</dc:creator>
    <dc:date>2019-01-14T08:02:46Z</dc:date>
  </entry>
  <entry>
    <title>Use npm scripts with AMD Module Loader in the frontend, e.g. webcontent</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111990199" />
    <author>
      <name>Severin Rohner</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111990199</id>
    <updated>2019-01-11T14:57:00Z</updated>
    <published>2019-01-11T14:57:00Z</published>
    <summary type="html">&lt;h1&gt;Working code in Liferay 7.0&lt;/h1&gt;
&lt;p&gt;In Liferay 7.0 we created an OSGI module with the JS code of a JS library.&lt;/p&gt;
&lt;p&gt;The code is copy paste from the dist to the file 'workspace/modules/dep-bricks/src/main/resources/META-INF/resources/Bricks.es.js'&lt;/p&gt;
&lt;p&gt;With following code in the build.graldes file:&lt;/p&gt;
&lt;pre&gt;
dependencies {
 compileOnly group: &amp;quot;com.liferay.portal&amp;quot;, name: &amp;quot;com.liferay.portal.kernel&amp;quot;, version: &amp;quot;2.0.0&amp;quot;
 compileOnly group: &amp;quot;com.liferay.portal&amp;quot;, name: &amp;quot;com.liferay.util.taglib&amp;quot;, version: &amp;quot;2.0.0&amp;quot;
 compileOnly group: &amp;quot;javax.servlet&amp;quot;, name: &amp;quot;javax.servlet-api&amp;quot;, version: &amp;quot;3.0.1&amp;quot;
 compileOnly group: &amp;quot;jstl&amp;quot;, name: &amp;quot;jstl&amp;quot;, version: &amp;quot;1.2&amp;quot;
 compileOnly group: &amp;quot;org.osgi&amp;quot;, name: &amp;quot;osgi.cmpn&amp;quot;, version: &amp;quot;6.0.0&amp;quot;
}

configJSModules {
 configVariable = &amp;quot;&amp;quot;
 ignorePath = false
 moduleExtension = &amp;quot;&amp;quot;
 moduleFormat = &amp;quot;/_/g,-&amp;quot;
 include &amp;quot;**/*.js*&amp;quot;
}&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;In the webcontent template we used this javascript code to load the
  bicks.js library, to load it only, if we need it.&lt;/p&gt;
&lt;pre&gt;
require('key-dep-bricks/Bricks.es', function(module) {
    var Bricks = module.default
    var bricksInstance = Bricks({
        ....
    })
})
&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;h1&gt;How to solve in Liferay 7.1&lt;/h1&gt;
&lt;p&gt;With Liferay 7.1.1 ga2 we get the new module loader (&amp;gt; V2.0.0)&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;Does anyone know how we have to create such dependencies
    module with the new module loader and how to consume it in the front end.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;Is it possible to use a npm dependency directly in the
    JavaScript require function, just with add it to the package json.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;As is saw in the documentation, there is the &lt;a
  href="https://dev.liferay.com/de/develop/tutorials/-/knowledge_base/7-1/using-the-npmresolver-api-in-your-portlets"&gt;NPMResolver&lt;/a&gt;,
  but how can I use this, if I don't like to create a portlet, because I
  will use the dependency in the theme or freemarker template?&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Thanks for your help.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Cheers Severin&lt;/p&gt;</summary>
    <dc:creator>Severin Rohner</dc:creator>
    <dc:date>2019-01-11T14:57:00Z</dc:date>
  </entry>
</feed>
