I use NPM and Gulp for my package manager and build system. I have installed "gulp-sass" to support sass, and "gulp-clean-css" so that I can @import css files inline. I capture my SCSS files in "_frontend/scss/**/*", and compiles that into a single file as "assets/frontend/css/styles.css". In the output location, I have other important resources folders that are siblings of "css": "fonts", "img", and "js".
My problem is I cannot get the url() relative paths to target correctly when I'm importing a "*.css" file. However, it is okay when I'm importing ".scss" files.
Here is my code (I took out sourcemaps, error log etc to simplify the question):
GULPFILE.JS
gulp.task('styles', function() {
gulp.src(styles.src)
.pipe(sassGlob()) // Support for bundle requires for Sass
.pipe(cleanCSS({
// relativeTo: './node_modules', <-- I tried with different variations here, no luck
// root: './node_modules', <-- I tried with different variations here, no luck
processImport: true
}))
.pipe(rename('styles.css')) // Name output CSS file
.pipe(gulp.dest('../assets/frontend/css/'));
});
MAIN.SCSS
The following is OK
@import "font-awesome/scss/font-awesome.scss";
Output seems to come out with the correct relative paths Sample output: url(../fonts/FontAwesome/fontawesome-webfont.eot?v=4.6.1)
The following is NOT
@import '../node_modules/jquery-ui/themes/base/jquery-ui.css';
Sample output: url(../node_modules/jquery-ui/themes/base/images/animated-overlay.gif) ^^ The above somehow appends the "../node_modules". I want it to somehow set this to "../img/vendor/jquery-ui/what/ever/i/like/here"
Here's my directory structure.
_frontend
├─fonts
│ ├─Beamstyle-Icons
│ └─Gotham-Light-Regular
├─node_modules
│ ├─jquery-ui
│ │ ├─scripts
│ │ └─themes
│ │ ├─base
│ │ ├─images
│ │ └─minified
│ │ └─images
│ └─ (other stuff...)
│
├─scripts
│ ├─app
│ └─vendor
└─scss
├─config
├─helpers
│ ├─classes
│ ├─functions
│ ├─mixins
│ └─placeholders
└─src
├─blocks
└─components
assets
└─frontend
├─css
├─fonts
├─img
│ ├─Beamstyle-Icons
│ ├─FontAwesome
│ └─Gotham-Light-Regular
└─js
Would be great if anyone can help on this.
For version < 2.4
use relativeTo
, root
and target
and if you don't want to rebase you can use rebase: false
configuration options.
For version >= 2.4
gulp-clean-css has been upgraded to use clean-css 4.x so none of the options above work and they only provide rebaseTo
option which will rebase all of your paths.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With