question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Slow nuxt startup when importing sass file

See original GitHub issue

Environment

  • Operating System: Linux
  • Node Version: v16.14.0
  • Nuxt Version: 3.0.0-rc.1
  • Package Manager: npm@8.3.1
  • Builder: vite
  • User Config: css
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-cimcyj

Describe the bug

I am using Bulma CSS with Nuxt app.

When I @import 'node_modules/bulma/bulma.sass'; in my '@/assets/main.scss' file. the nuxt startup becomes too slow. It takes around 20-60 seconds for vite client and server to warm up.

image

Currently I have app running with nuxt3@3.0.0-27460489.53fbca7 without this issue.

Additional context

No response

Logs

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
dulnancommented, Dec 6, 2022

tl;dr Replace custom divide function with math.div.

After some longer profiling and debugging I think I found out the actual reason for very slow warm ups and builds (mine took anywhere from 20 seconds to 2 minutes). At least in my case it reduced the build time significantly.

Both Bulma and Bootstrap have a magic divide function that reimplements… dividing numbers. Originally this was implemented in Bootstrap and Bulma copied that code from there, but Bootstrap has since then “updated” the function to be more “efficient”:

https://github.com/twbs/bootstrap/blob/main/scss/_functions.scss#L262

Here’s Bulma’s code (based on an older version from Bootstrap): https://github.com/jgthms/bulma/blob/master/sass/utilities/functions.sass#L118

The main issue seems to be a while loop, looping itself into oblivion. After replacing it with math.div() from sass:math, the warm up time dropped down to 4 seconds from 22 seconds. I have also tried the improved version from Bootstrap, which reduced the same build time to 16 seconds.

Now calling this function just a few dozen times in the beginning might not be an issue, but if you have dozens of SCSS files, components with styles and you’re using additionalData to provide global variables, you’ll end up running that inefficient code hundreds of times. Which adds up to a lot, hence why builds take ages.

0reactions
issue-up[bot]commented, Dec 6, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuxt build on locale is extremly slow - Stack Overflow
There is nothing really shocking here in terms of configuration ( nuxt.config.js ). So I guess that it depends on what is running...
Read more >
Globally accessible CSS and SCSS/ SASS in your Nuxt ...
To import global css, open your nuxt.config.js file and navigate to the ... component and will also make your build/HMR magnitudes slower.
Read more >
Experiencing too long compile times while developing : r/Nuxt
I am developing a Nuxt app. My target mode is static. While developing the app, it takes long times, 17s to 26s.
Read more >
Using Sass In Nuxt.js - DEV Community ‍ ‍
So if you're just starting a new project, consider learning Dart Sass instead. sass-loader@10 loads each Sass/SCSS file and compiles them to CSS...
Read more >
Server-side rendering with Vue and Nuxt.js - LogRocket Blog
When using a JavaScript framework such as Vue, the source file will ... For those without knowledge of Vue.js, consider starting from the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found