Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Using SPA Frameworks to build DXP Fragments (Sections, Components)
Is it possible to use a SPA framework (e.g., React, Vue) to build one of the new DXP fragments? (presumably using the CLI)If so are there any pointers/samples available?
In general yes. I wrote a blog post how we write our applications nowadays and the same could be done with fragments. Of course, this is just one way, with pros and cons.
https://liferay.dev/blogs/-/blogs/developing-javascript-frontends-with-webpack
Basically:
1) We add javascript to the page that registers a webcomponent (note: this only works in IE with the proper polyfills). Even with polyfills, that javascript is pretty small.
2) The moment a tag <hello-world></hello-world> is added to the page, connectedCallback is executed and hello.js is loaded dynamically. It could be a react app, then it would load also react and all dependencies.
So, you could simply add the javascript globally and put the tag in a fragment and it would work. The overhead of the "init" javascript is rather small, especially since everything else is lazy loaded.
https://liferay.dev/blogs/-/blogs/developing-javascript-frontends-with-webpack
Basically:
1) We add javascript to the page that registers a webcomponent (note: this only works in IE with the proper polyfills). Even with polyfills, that javascript is pretty small.
class HelloWorld extends HTMLElement { |
connectedCallback() { |
import( './components/Hello/hello.js').then(module => { |
module.default(this); |
}).catch(error => console.error('An error occurred while loading the component `HelloWorld`', error)); |
} |
} |
register('hello-world', HelloWorld); |
So, you could simply add the javascript globally and put the tag in a fragment and it would work. The overhead of the "init" javascript is rather small, especially since everything else is lazy loaded.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™