lucleray / next-purgecss

nextjs + purgecss for smaller css bundles
https://www.npmjs.com/package/next-purgecss
134 stars 8 forks source link

Basic Sass Example Problem - Running Build From Another Folder #7

Closed tteltrab closed 5 years ago

tteltrab commented 5 years ago

Running into an issue trying to get this set up with basic Sass. Not doing anything exciting here:

image

Here's my next.config.js

image

I think this might be a package problem (would need to investigate the package further to confirm), as my setup is pretty vanilla? Could be on my end, though. Here's my folder structure - pretty basic:

image

Am I missing some requirement/setup piece? Thanks!

lucleray commented 5 years ago

I created an example that works here : https://github.com/lucleray/next-purgecss/tree/master/examples/sass

Maybe there's a bug because main.scss is in pages (i would recommend to move it to a different folder) ? You also need to install node-sass , can you check you have it installed ?

I'm not sure what your bug is 🤔

tteltrab commented 5 years ago

Thanks for the example! I think I figured out the problem.

I'm currently running the build one folder up from the frontend folder (my package.json is running next build frontend). Your example works for me, and if I move into the folder and run the build, the package works as well for my example.

image

I think as a result of using process.cwd() in the glob pattern, the glob is looking in the folder running the task, not the folder next is associated with (so ~/my-package/(pages|components)/**/* instead of ~/my-package/frontend/(pages|components)/**/*).

My use case would work if the code used config.context (getting the path through the webpack config being used by next), instead of process.cwd() - I think that might be a solution that works more generally? Happy to make a PR if you agree.

(I pulled down the repo, made the change, did a link, and tested it - fixed my problem, and still works on existing example).

lucleray commented 5 years ago

Thanks for spotting the issue. Using config.context seems to be the good way to do this 👍

Thanks for the PR !