-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Watch doesn't trigger while processing scss with Gulp #607
Comments
Hey thanks for all the details, I am looking into debugging but my main question is why you are compiling scss to css and then outputting it to the assets folder with the |
Okay so I have not been able to reproduce this even with your gulp script and your setup. The only way I have been able to reproduce the behaviour is by running the |
Hi Tanema, many thanks for looking into this. I might be wrong (I am still very new to Shopify and ThemeKit) but I don't think Shopify likes SASS's I have all my colour variables on their own colours.scss file, same with typography.scss, utils.scss, buttons.scss etc. They all contain variables and mixins I use on other .scss files. If I had all these in the assets directory wouldn't Shopify just compile them all as individual .css files? However I do think my gulpfile.js could be streamlined - there's probably no need for |
Hmm strange... perhaps it's a caching thing on Terminal or my environment? Yes, I have tested to make sure and there definitely are changes on the compiled file (the way I've been uploading quick css fixes to my site is I've compiled the .css file with my changes, then manually added a line-break to the bottom of the .css file to trigger Weirdly enough too, Many thanks for looking into this again. |
I am able to reproduce this challenge with the following gulpfile: const { task, watch, src, dest, series } = require('gulp');
const sass = require('gulp-sass');
const autoprefix = require('gulp-autoprefixer');
sass.compiler = require('node-sass');
function scss(cb) {
src('./src/scss/**/*.scss')
.pipe(sass({outputStyle: 'expanded'}))
.on('error', sass.logError)
.pipe(autoprefix({
browsers: ['> 2%', 'ie >= 10'],
grid: true
}))
.pipe(dest('./assets/'));
cb();
}
function watcher(cb) {
watch('./src/scss/**/*.scss', series(scss))
cb()
}
module.default = task('default', series([scss, watcher])); File Structure:
The problem didn't happen prior to the 1.0.0 update. Funny enough, I can create a newline in the compiled css file, delete the same line, save it and Shopify Theme Kit will detect that and subsequent compiled changes for 2-3 more changes before it starts ignoring the compiled output again. Like @AdamDSherman, I have several partial imports, including a _variables.scss file. I'm not sure that Shopify handles autoprefixing in addition to imports, so I would prefer that this tool watch consistently as well. I'd contribute something more substantial but I don't speak go (yet?) Thanks so much!! |
Just some more info if it's useful: I recently have updated my above gulpfile.js to use |
Thank you for all your information, I still cannot reproduce it for some reason. So here we go with a full deep dive: Here is what I am usingGulp version 4.0 package.json
Gulpfile.js What I am doing
All of the changes are picked up by uploading Lastly I appreciate your help and patience while we get this fixed! |
@tanema - I'm not running any sort of task runner, or even npm, outside of gulp itself. I just head over to my project root and type I'm fairly sure this isn't related, but just in case it is, I did not run the themekit install script. I just read the script over and determined which binary to download and add to my local bin path that's exported in my .zshenv. I use Arch, btw (memes aside). |
@trev-dev Re: Usage I was actually able to reproduce this now but only for my |
@tanema I was inspecting the install script to see how it worked (I try to sandbox as much software as I much as I possibly can to my local user) and figured out where the binary comes from and how it's run and just went "Oh, this is straight forward" and downloaded it myself :) - I didn't even try to run the script. Thanks for sticking with us. |
Okay so I have noticed that when I change The newest implementation uses polling based on checksums and timestamps and no longer uses inotify for linux and kqueue for OSX. (library for reference) This means that if your tool, gulp in this instance does not change the mod time on a file themekit won't pick it up. I will look into a way we can make this better through the library. I believe what it does currently is first check the time and then check the checksum but maybe we can make it do both. For now as a workaround I found a gulp lib called gulp-touch that would touch the file for every modification and made this change to my gulpfile.js
I hope this speeds up your development again and I will hopefully have a more official fix for you in the future. |
We seem to be getting a similar issue. Themekit 0.8.1 When we update an existing class it updates the assets file just fine. when we add a new class it doesn't. the main.min.css it compiles into has the updated code it just isn't then sending it over to the shopify theme . note this only happens on |
I didn't even realize that you could modify a file without implicitly modifying the timestamp. I wonder if this is something the folks at Gulp would find handy. |
Of course, I went and had a look and found gulpjs/gulp#2193 @tanema ...so it appears its a gulp issue first and a Shopify Themekit issue second. |
So it seems like will not be fixed in Gulp, we will have to find ways of handling it downstream and it sounds like they even suggest something like my Edit: It seems like even in the other issues linked in the gulp issue, other developers have solved this in a similar way. |
@tanema Love the accountability for your user experience. For what it's worth, Gulp is sorta looking into it too, it's been offloaded into another issue but it has been open for |
As a note for the future as @richyrb00 has mentioned that older versions are broken, this is not a change in themekit that caused this but rather a change in Gulp and/or Node. I recommend using |
gulp-touch (and similar gulp-touch-xxx) npm packages are 2 years out of date and don't appear to be working for gulp 4, FYI. I was able to achieve results using through2 which will accept a Writeable stream and allow me to change the atime/mtime. const { task, watch, src, dest, series } = require('gulp');
const sass = require('gulp-sass');
const autoprefix = require('gulp-autoprefixer');
const t2 = require('through2'); // Get through2 as t2
sass.compiler = require('node-sass');
function scss(cb) {
src('./src/scss/**/*.scss')
.pipe(sass({outputStyle: 'expanded'}))
.on('error', sass.logError)
.pipe(autoprefix({
browsers: ['> 2%', 'ie >= 10'],
grid: true
}))
.pipe(t2.obj((chunk, enc, cb) => { // Execute through2
let date = new Date();
chunk.stat.atime = date;
chunk.stat.mtime = date;
cb(null, chunk);
}))
.pipe(dest('./assets/'))
cb();
}
function watcher(cb) {
watch('./src/scss/**/*.scss', series(scss))
cb()
}
module.default = task('default', series([scss, watcher])); This is working like a charm for me. |
@trev-dev thank you so much for the update I am sure others will appreciate it! |
Thanks trev-dev, you rock... |
I couldn't get Trev-Dev's solution working for me, so came up with an alternative. Here's a stripped-down version. I essentially run a seperate Gulp Watch on the generated CSS file, and perform a 'deploy' on that specific file.
|
I just ran across this.. As @tanema notes above, it seems to because the timestamp does not change. There are a few options, like gulp-touch (or gulp-touch-fd better, for use with Gulp 4). I liked this one from stackoverflow:
|
@rickydazla and @trev-dev I'm glad you found my little pipe function useful! I've updated it to be better and more reusable: import through2 from 'through2';
const touch = () => through2.obj( function( file, enc, cb ) {
if ( file.stat ) {
file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
}
cb( null, file );
}); So you can use function sassDev() {
return gulp.src( sassFiles )
.pipe( sourcemaps.init() )
.pipe( sass() )
.pipe( postcss() )
.pipe( sourcemaps.write() )
.pipe( touch() )
.pipe( gulp.dest( sassDest ) );
} |
Brilliant! Thanks so much! Works! |
Not sure if it's a gulp problem or not but since updating to |
Describe the bug
I am using Gulp to compile several .scss files into my main theme.scss.css file (which is in the assets directory). This works fine, but Theme Watch doesn't recognise when the theme.scss.css file has been updated when recompiled. However, if I manually update the theme.scss.css file in my IDE it will recognise the change and push up to the remote server.
Working with other normal section, asset and snippet files works fine -
theme watch
detects the change and pushes them up.To Reproduce
Steps to reproduce the behavior:
theme watch
gulp do-sass
commandtheme watch
may push up the first set of changes to theme.scss.css, but not any subsequent changesExpected behavior
A clear and concise description of what you expected to happen.
Environment (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: