# How to add Javascript the right way in Sage10

**URL:** https://discourse.roots.io/t/how-to-add-javascript-the-right-way-in-sage10/25047
**Category:** sage
**Tags:** sage10
**Created:** 2023-03-29T14:44:09Z
**Posts:** 8
**Showing post:** 2 of 8

## Post 2 by @csorrentino — 2023-03-29T15:12:19Z

Here’s a link that should get you started: [Modules, introduction](https://javascript.info/modules-intro)

If I’m understanding your question, you’re looking to break up your app.js file into modules. Here’s a simplified example from a recent project:

**/resources/scrpts/animations.js**

```
export const animations = async (err) => {
  if (err) {
    console.error(err);
  }

  // ...
};

import.meta.webpackHot?.accept(animations);
```

**/resources/scripts/app.js**

```
import domReady from '@roots/sage/client/dom-ready';
import {animations} from './animations.js';

/**
 * Application entrypoint
 */
domReady(async () => {
  animations();
});

/**
 * @see {@link https://webpack.js.org/api/hot-module-replacement/}
 */
import.meta.webpackHot?.accept(console.error);
```

---

_[View the full topic](https://discourse.roots.io/t/how-to-add-javascript-the-right-way-in-sage10/25047)._
