webdeb / next-styles

CSS + SASS + CssModules in Next.js
40 stars 6 forks source link

unable to get hot reload working #4

Closed akhatri closed 4 years ago

akhatri commented 4 years ago

Firstly this plugin does what I want, allowing both SASS modules and global SASS for my project :) so thanks for this. It works as expected but I cant seem to get hot reload working unless i manually refresh the page. is there something wrong with my config file? I am using Nextjs 9.2 with typescript

next.config.js

const withStyles = require('@webdeb/next-styles')

module.exports = withStyles({
  sass: true, // use .scss files
  modules: true, // style.(m|module).css & style.(m|module).scss for module files
  sassLoaderOptions: {
    sassOptions: {
      includePaths: ["assets/styles"]
    },
  },
  cssLoaderOptions: {},
  postcssLoaderOptions: {}
});

I have title.module.scss in the root of the project and I reference it in the index.tsx I have global.scss in the assets/styles folder

index.tsx

// Global CSS
import '../assets/styles/global.scss';

// CSS Modules
import css from '../title.module.scss';

package.json

  "dependencies": {
    "@webdeb/next-styles": "^1.0.3",
    "@zeit/next-sass": "^1.0.1",
    "next": "^9.2.0",
    "node-sass": "^4.13.1",
    "react": "^16.12.0",
    "react-dom": "^16.12.0"
  },
  "devDependencies": {
    "@types/node": "^13.1.8",
    "@types/react": "^16.9.18",
    "typescript": "^3.7.5"
  }
webdeb commented 4 years ago

Hi, thank you for reporting this bug.

I am not sure, but I think it is related to how nextjs handles hot modules upgrades. This package uses some newer packages then next-css, so the config is slightly different, some parts are based on CRA configuration.After having a briefly look into this, I was not able to find the problem, need to dig deeper.

Please, if it is urgent for you, feel free to take a look, and if you can find the problem, it would be very helpful.

webdeb commented 4 years ago

Fixed in 1.0.4, please try if it is working for you

webdeb commented 4 years ago

sry. had to republish, try 1.0.5

akhatri commented 4 years ago

@webdeb just tested it and it works :) thanks for the quick turnaround. Amazing plugin