How to hot module replacement local npm package that I'm developing in server side rendered react, node.js app, in cezerin for example

Viewed 121

I'm developing a local npm package called 'theme' in a server side rendered react, node.js app called cezerin(https://github.com/cezerin/cezerin/issues/560).

Currently it's running with pm2 both api, storefront and it's watching file changes in local package theme. However, it doesn't restart the server automatically when I change the look by changing the code in the theme.

{
    "apps": [
        {
            "name": "api",
            "cwd": "./src/api/server",
            "args": [],
            "script": "index.js",
            "node_args":"cross-env NODE_ENV=development",
            "watch": ["./config/server.js", "./src/api/server/"],
            "instances": "1",
            "exec_mode": "fork",
            "watch_options": {
                "persistent": true,
                "ignoreInitial": false
            }
        },
        {
            "name": "store",
            "cwd": "./src/store/server",
            "args": [],
            "script": "index.js",
            "node_args":"cross-env NODE_ENV=development",
            "watch": [
                "./config/server.js",
                "./store/",
                "./theme/",
                "./theme/assets/index.html"
            ],
            "instances": "1",
            "exec_mode": "fork",
            "watch_options": {
                "persistent": true,
                "ignoreInitial": false
            }
        }
    ]
}

How does everyone set up development mode when you want to see the change instantly as you change the code in local theme that you are developing?

1 Answers

You need to run your cezerin app with "watch" option.

npm run build:watch

By default cezerin2 support watchers.

github.com/cezerin2

With the "watch" option all or your changes available after page reload at browser.

If you can't see changes, try to clear service worker at chrome dev console - Application - Service Wroker - Unregister and reload the page.

Related