Compiling LESS with mapping. How to set relative path for sources? - css

I have some problems with creating a proper .map file.
I compile by this way:
lessc --source-map=styles.map styles.less styles.css
The problem is that the path to the sources files is a full local path. It looks like this (quote from the beginning of styles.map):
{"version":3,"sources":["C:/xampp/htdocs/Projects/TestSite/wp-content/themes/wordpress-bootstrap-master/bower_components/bootstrap/less/normalize.less"
...
After uploading to server, all the paths to source files are accepted in a wrong way.
If I replace all C:/xampp/htdocs/Projects/TestSite with an empty string, it becomes well.
What settings should I do to get a right .map file?
I tested --source-map-less-inline; it includes all of the Less files in to the sourcemap, so it goes well, but by this way the .map file becomes very big.

Related

How to use gulp-clean-css to write a new -min.css file instead of the default of overwriting the existing css source file?

How to use gulp-clean-css to write a new -min.css file instead of the default of overwriting the existing CSS source file?
Currently, I have this line which minifies the file. However, it overwrites the original with the minified version. I would like it to create a new file with the -min.css extension at the end of the original file basename.
src(filePath).pipe(minifyCSS()).pipe(dest('./css/'));
I know there is a gulp-copy in the npm repo I could use. I would like to know if there are any other ways to do it.
Thanks
I don't believe this is possible without installing any additional npm packages, though considering the nature of NodeJS, I don't think it would be considered unreasonable to require one.
One possible way to achieve this (without gulp-copy) would be with gulp-rename and the rename command:
gulp.src(config.css)
// Output the file before cleaning
.pipe(gulp.dest(config.css))
// Clean the file
.pipe(cleanCss())
// Rename with a .min suffix (e.g. app.css -> app.min.css)
.pipe(rename({ suffix: ".min" }))
// Output the minified CSS file
.pipe(gulp.dest(config.css));
This will produce two files - the unminified original .css file and the minified .min.css file.

How should I structure sass and css in my project

I'm a newbie to Sass and try to create a folder structure which works with minimal effort when compiling. I want to create multiple files in each multiple directories which have the same name with the file (/.css) and my sass files are located in app/sass folder so that it's transferred with no effort.
I've done a research for the simple tricks of cd notation of any command line but later I understood that the notation of Sass can be different. I've looked for Gulp and Grunt and still couldn't find exactly anything on sending css files to multiple destinations which have the same name. I've searched Sass/CSS structures but I still cannot figure it out how to use a single CSS file for the entire project.
-app
-sass
-index.scss
-admin.scss
-public
-index
-index.css
-admin
-admin.css
sass --watch app/sass/*.scss:public/css/*/*.css
What should I write instead of * that functions as a parameter for everyone?
The Sass guide on their website: https://sass-lang.com/guide tells you to do it like this:
sass --watch app/sass:public/stylesheets
And this link [
sass watching multiple directories
] says you can specify more then one path to watch:
sass --watch path/to/sass1:path/to/css1 path/to/sass2:path/to/css2 path/to/sass3:path/to/css3
So you can watch multiple paths, but still have to specify each of them.

Elixir: equivalent of scriptsIn for less files (concat + compile less files in one css file)?

I'd like to concat+compile all the less files of one folder into a specified css file.
It works well with JS scripts, using the scriptsIn function but I can't find an equivalent for less files.
I've read this thread: Laravel Elixir - Compile/concat all less files into one css file? but don't find it very useful since I don't want to know what's in my folder (I don't know how many different less files there are in it).
I'd like to write something like that, if possible:
elixir(function(mix) {
mix.lessIn('resources/assets/less/myfolder', 'public/css/myfolder.css');
})
I updated laravel-elixir to version 5.0.0 and now this works well:
elixir(function(mix) {
mix.less('resources/assets/less/myfolder/*.less', 'public/css/myfolder.css');
})

How to concatenate (and not compile) several less files into one using grunt

I'm having trouble finding a solution to this problem. I have a less file app.less that only consists of #import statements. Now I want to generate a single less file that includes all imported less files, because I want to send it to the client to compile it there (yes, I have my reasons to do that).
So the less file should not be compiled in the grunt build step, but only concatenated, so that the client doesn't have to load several less files. I feel that this is a usecase that should have appeared for others as well when compiling less on the client, but I couldn't find a single solution. I don't care if the concatenation happens with grunt-contrib-less or any other tool.
LESS docs says:
Use #import (inline) to include external files, but not process them.
See: Import At-Rules and #import (inline)
You could create new file, for example concatenate.less and import .less files with inline keyword. Then if you process it, it will work exactly like concatenation, no CSS is processed out of it.
concatenate.less
#import (inline) "file1.less"
#import (inline) "file2.less"
#import (inline) "file3.less"
And use your Grunt task like you used to, just rename output file extension to .less for clarity. Tested it, should give you exactly what you wanted.
Nested imports
As #seven-phases-max pointed out, that nested imports would be problem in this case.
Solution would be grunt-includes.
Use grunt-includes with includeRegexp option to create files listed in concatenate.less with already imported LESS files to some other folder.
Change concatenate.less files paths to that folder.
Run your LESS compiling Grunt task normally.
in case someone is working with gulp,
you can just create concatenate.less as #Rene Korss sugested, and use the same command as for compiling less.
Less outputs concatenate.css filename, which is misleading in our case,
so I'm using gulp-rename to have filename named as I want.
var src = 'path-to-concatenate-less-file';
var destination = 'path-to-destination';
gulp.task('concatenate-styles', function () {
var compile= gulp.src(src)
.pipe(less())
.pipe(rename('concatenate-all.less'))
.pipe(gulp.dest(destination))
.pipe(notify("Saved file: <%= file.relative %>!"));
compile.on('error', console.error.bind(console));
return compile;
});
Example of concatenate.less:
#import (inline) "general.less";
#import (inline) "typography.less";

How to let less2css compile all files once one of the less file is saved?

I have style.less which import "page.less". When something is changed in page.less, I have to turn to file style.less and save to let less2css compile so that the changes will take effect otherwise it doesn't because page.less is imported! So is there a way to let less2css compile all files when one of them is changed?
Assuming you're already using the LESS-build you can use SublimOnSaveBuild. This would also work in other scopes.
Alternatively, there's a LESS-only package for Sublime Text as well.

Resources