This repository was archived by the owner on Jan 18, 2022. It is now read-only.
This repository was archived by the owner on Jan 18, 2022. It is now read-only.
change imported stylesheet not trigger recompiling #286
Open
Description
Version
5.0.0
Steps to reproduce
- create a component with <style lang="scss">
- import another stylesheet via
@import './another-stylesheet';
- run rollup with minimal config and watch mode
- change the styles in
another-stylesheet
What is expected?
recompile the style
What is actually happening?
do nothing
change the styles in style block can trigger recompiling but didn't work for its dependencies(stylesheet imported in style block)
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
[-]changed imported stylesheet not trigger recompiling [/-][+]change imported stylesheet not trigger recompiling [/+]TomCaserta commentedon Jun 13, 2019
Also doesn't work for external style files using
<style src='X' />
. Seems to be because this plugin doesn't callthis.addWatchFile
to notify rollup that theres a dependency on another file.Get's a bit tricky as this plugin utilises vue compiler utils which actually performs the style compilation (instead of deferring to rollup) and therefore it has no idea what style files import other style files so it can't tell rollup what files to watch.
morficus commentedon Sep 3, 2019
I belie this is related to #268
wbern commentedon Jun 15, 2020
Because of my inexperience with rollup, my workarounds in previous posts were not perfect, so I deleted those posts to not bloat this issue. I did arrive at a pretty good solution in in the end however, at cost of variable performance.
This work-around is a rollup plugin which seems to patch up most issues, but I've imposed my own limitations on it to not drain performance too much, which I'll explain further down.
rollup-plugin-vue-scss-watcher-glob.js
rollup.config.js
This rollup plugin will watch Vue-referenced .scss files for changes (the transform method), if the .scss file has the same name as the .Vue file. You can fix that to be more broad, but be wary of performance issues. The drawback of only using the transform method is that it won't watch scss files that you modify that your "main" scss file depends on.
That's why I added "onBuildStart" hook, which will watch all scss files inside all "src" directories in my org's monorepo. You can modify that however you want, it's just the
globby
pattern exposed to the rollup.config.js. Initially I had some logic to prevent watching files that I had already donethis.addWatchFile()
on, but rollup seems to prune those watched files by itself, so I removed all that caching logic.Combining these two seems to trigger changes in all relevant scss files, as well as Vue files.
vladiiliev commentedon Oct 2, 2021
Hey, is there any progress on this? Because we face the same issue :(
wbern commentedon Oct 2, 2021
@vladiiliev did you try the above workaround?
vladiiliev commentedon Oct 3, 2021
Yes, and unfortunately it doesn't work completely (for us). The *.scss files are added to the queue with the watched files, but the code changes are not reflected in the output bundle.
But our case is a little different. We have scss partials that are imported into the scss of the component. For example:
The changes in the file
variables.scss
are watched, but as I already mentioned there is no change in the output bundle.vladiiliev commentedon Oct 4, 2021
I created a plugin to cover the functionality we need. Successfully watches scss partials added with @import.
https://www.npmjs.com/package/rollup-plugin-watcher