Roots Discourse

Scripts Don't Seems To Be Loading

Hello, I’m new to Sage and WordPress in general. I’m running a basic setup, out of the box. I’ve added console.log('ready..'); to my main.js in the normal sage install location, just for a simple yest, and yet I do not see any console logs.

Any ideas? This must be some simple thing that I’m not picking up on. Thanks for any help!

Are you running yarn build (or npm run build) to compile the JavaScript first?

I’m using NPM for commands. I haven’t run build though, since I’m in dev I just run npm run start and webpack compiles. So, if I save a change in say, main.js it says “Compiling” … So, do I also need to run npm run build every time I make a .js file change?

No, npm run start will suffice.

I suspect that since you are adding the console.log statement to main.js (the entry) as opposed to the routes/common.js (a module), it’s not able to inject the updated via HMR. I could be horribly wrong though.

What happens when you run npm run build and just view the site in the browser?

Crazy enough, with npm run build I get the console logs. I think one thing is apparent though, I should put stuff I to common.js or maybe a .js file I make in autoload?

Thanks for the help!

In Sage 9, we’re using the DOM router for scoping code per route. For (most) common code, you can put it within the init function of the default export in routes/common.js. The autoload directory is intended to be used by Sage 9 presets.

Great, thank you very much for your help, it seems to be working now! :smiley:

1 Like

This topic was automatically closed after 42 days. New replies are no longer allowed.