Setting up frontend dev-server for AEM
Summary
If you generated AEM project with AEM project archetype, you can start dev server by running cd ui.frontend && npm run watch
but it does not somehow reflect changes you make in the css files immidiately.
In this article, I'll show you how to set up front-end development environment that reflects changes immediately that boosts up your UI development speed on AEM.
Prerequisites
First, change the start
command in package.json
to the following:
By default, webpack-dev-server serves the bundled files from memory for better performance during development. By doing this, webpack-dev-server will write to disk instead of keeping them only in memory.
You can still work on port 4502 but 8080 reloads much faster.
Using webpack-dev-server
In your local author instance, go to any page and click View as published
and view page source and copy the entire html content.
Then, go to ui.frontend/src/main/webpack/index.html
and paste the content into index.html
.
In the HTML you pasted, remove the <link/>
and <script/>
tags that include clientlib-site
or clientlib-dependencies
.
Here is the shell command to remove the <link/>
and <script/>
tags that include clientlib-site
or clientlib-dependencies
.
Now you can cd ui.frontend && npm start
and visit http://localhost:8080
.
You can update your css files and see changes immediately. This is very useful when you are developing UI for AEM.
Happy hacking.