First time using Sage and main.js is not compiling when files change

sage9

#1

This is the first time using this theme. I think the concept is great, but whenever I make code additions to resources/assets/scripts/routes/home.js, dist/scripts/main.js does not compile. I have to go back to terminal, stop the yarn process, and run yarn run start again. THEN it compiles. This cannot be the correct behavior, right?


#2

This cannot be the correct behavior, right?

Nope. It is when you add new files, it needs a new build then in order to recognize changes but that shouldn’t be happening on existing files / directives.

Does the (S)CSS work fine? Any errors / console statements? Are all of Sage’s dependencies up to date?


#3

Hi,

do you have right theme folder in config.json? Could you send us your config?

Martin.


#4

Here is my config.json file. SCSS doesn’t compile at, and even when I start yarn run start it doesn’t create a dist/styles/main.css file either, but it DOES create a dist/scripts/main.js file, but only when running yarn run start not when files have been modified while webpack is running. My test Sage theme is located in wp-content/app/themes/sage but before putting it in the app folder, which I never have really done with wordpress themes before, the same issue is happening when I installed sage into wp-content/themes/sage

{
  "entry": {
    "main": [
      "./scripts/main.js",
      "./styles/main.scss"
    ],
    "customizer": [
      "./scripts/customizer.js"
    ]
  },
  "publicPath": "/app/themes/sage",
  "devUrl": "http://www.sagetest.local",
  "proxyUrl": "http://localhost:3000",
  "cacheBusting": "[name]_[hash:8]",
  "watch": [
    "app/**/*.php",
    "config/**/*.php",
    "resources/views/**/*.php"
  ]
}

#5

Also, whenever I make a change to the main.js file, it does say it compiled, but the main.js file does not update. However, i do see my change in one of the json files in the .cache-loader folder too


#6

All of my tests have been run just by doing composer create-project roots/sage sage dev-master so I assume it’s up to date? I have node 9.11.1 and npm 5.6.0 installed too, if that helps.


#7

Sorry, first time using discourse :smiley: See my reply above


#8

Yes, they are all up to date, and I am using the composer create-project roots/sage sage dev-master command to download and set up the theme


#9

Hi, move Sage theme to /wp-content/themes/sage then change “publicPath” in your config to /wp-content/themes/sage, delete .cache-loader forlder and dist folder (if exist) and after this steps try yarn run start if it works.


#10

So your main.css is not being compiled correctly? If so then you should inspect that, seems to be a more general issue. Any errors being thrown?

Also, whenever I make a change to the main.js file, it does say it compiled, but the main.js file does not update. However, i do see my change in one of the json files in the .cache-loader folder too

If I’m not mistaken then the changes you make are virtually injected into the file and thus you won’t see the actual file changing until you re-build.

Please run a test with a simple console.log or whatever and see if the new code is being injected & executed. If so then I don’t know why you would be worried…


#11

@Martin_Kucera I did what you said, but nothing. I also tried deleting the .cache-loader folder while yarn/webpack was running and tried adding code to resources/assets/scripts/routes/home.js as well as resources/assets/scripts/main.js, but that didn’t work. I also removed the dist folder while yarn was running too and retried adding new code to the .JS files, but that didn’t work either.


#12

I also just downgraded my node to 8.11.1 to make sure that wasn’t it. re-ran yarn and did yarn run start but still no dice


#13

Another weird thing is I don’t even see this being used in webpack, not sure if that’s an issue, but. Just trying to rubber duck as much as I can.


#14

@evance Yeah, none of it compiles while yarn is running. I am checking the dist folder after adding simple code. If I add bad CSS to the SCSS file, I do get errors saying it’s malformed, but once i fix the error, the main.css still doesn’t compile. I am used to using gulp on a handful of projects, so whenever I make changes to custom JS or SCSS files, they get processed / minified / stored into a specific folder I configured in the gulp file. Sage however, is not using that workflow. The assets only get compiled when I run yarn run start. So if I make a change to any asset that’s supposed to get compiled. I need to halt yarn, and do yarn run start to compile it.


#15

Here’s an example video of the issue I am having:


#16

Please run a test with a simple console_log or whatever and see if the new code is being injected & executed. If so then I don’t know why you would be worried…

Did you do this? In simple steps:

  • yarn run start
  • edit common.js and introduce a simple console.log, onClick or similar
  • check the output (force a re-load if necessary)

I am checking the dist folder after adding simple code.

Pretty sure that you won’t see any actual file edits so it’s pointless to check. The code is injected and only changes upon a new build.


#17

@evance Still no dice. I did both a console.log and an alert in resources/assets/scripts/routes/common.js and resources/assets/scripts/main.js, and I don’t see anything popping up or getting written out in console. Even though webpack says it compiled. I think halt webpack/yarn, and do yarn run start again, then THEN the console.log and alert works.

I also didn’t use dev-master to build the theme this time, I used the stable version.

I am going to try it on my mac mini to see if that works, since that environment is different in a certain sense. Not much is installed as far as webdev libs


#18

I just tried to compile the main.js on an entirely different machine (mac mini) with a fresh install of composer, and yarn, but that still doesn’t compile down while webpack is running after making a change to common.js or main.js. I am at a loss here.


#19

OK, I can confirm that the JS doesn’t inject properly with my current setup as well…

Unfortunately all I can do is to direct you to this thread which may or may not have additional info on the issue.

Can somebody else chip in? Any thoughts?


#20

@evance @Martin_Kucera Great news. I have it working now. I tried the whole installation process again tonight, and I noticed that in the README.md file, they changed the command to start webpack. It’s now yarn start instead of yarn run start. I can now confirm that styles and scripts are now being injected into the browser!

Thanks for all your help on this, and sorry for the frustration. It was frustrating me as well, but glad it’s all sorted out. I am wondering if the yarn command was wrong in the first place in the README.md or what?

Thanks!