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.

URL rebasing from index.html

See original GitHub issue

Hi

I’m using gulp-clean-css with the version 3.4.23. I’m trying to pack all css files into one, loading it from the index.html

<!-- application css --> <link rel="stylesheet" type="text/css" href="style/application/bootstrap.css"> <!-- endbuild -->

And in the gulp

return gulp.src('src/index.html') .pipe(gulpif('*.css', cleanCSS({options}))) .pipe(uncache()) .pipe(gulp.dest(buildDir));

What options should use to properly rebase the url() inside css file. Resources from url can be allocated in different folders, and they are copy to buildDir. Like: src/a/b/image.png -> buildDir/a/b/image.png

I was playing with relativeTo, target, root, rebase(true/false) and nothing seems to work.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:32

github_iconTop GitHub Comments

2reactions
jakubpawlowiczcommented, Jan 10, 2017

This is odd.

I assume you don’t use rebase: false as an option, right? Does the same thing happen with image URLs as well?

1reaction
jakubpawlowiczcommented, Jan 25, 2017

Re 1 - that’s because you need to point relativeTo differently, e.g. this works fine:

var gulp = require('gulp');
var useref = require('gulp-useref');
var cleanCSS = require('gulp-clean-css');
var gulpif = require('gulp-if');
var uncache = require('gulp-uncache');

var targetDir = 'dist';

gulp.task('lib-resources', function () {
  return gulp.src(['src/lib/**/*', '!src/lib/**/*.css'], { base: 'src' })
    .pipe(gulp.dest(targetDir));
});

gulp.task('build', ['lib-resources'], function () {
  return gulp.src('src/index.html')
    .pipe(useref())
    .pipe(gulpif('*.css', cleanCSS({ target: 'src', relativeTo: 'src/resource' })))
    .pipe(uncache())
    .pipe(gulp.dest(targetDir));
});

Re 2 - this is not up to clean-css as it receives a piped file from gulp, namely useref plugin. I’m pretty sure you can patch useref to turn all <link... statements into @import rules, so do the current manual application.css step in-memory.

Read more comments on GitHub >

github_iconTop Results From Across the Web

URL rebasing from index.html #854 - clean-css/clean ... - GitHub
Hi I'm using gulp-clean-css with the version 3.4.23. I'm trying to pack all css files into one, loading it from the index.html.
Read more >
URL rebasing feature - Stack Overflow
1) With Html elements that don't have runat = “server” attribute, absolute and relative paths are sent to the browser as they are....
Read more >
HTML::Rebase - rewrite HTML links to be relative to a given URL
Rewrites all HTML links to be relative to the given URL. This only rewrites things that look like src= and href= attributes. Unquoted...
Read more >
Rebasing - Ry's Git Tutorial - RyPress - hamwaves.com
First, make a new directory in my-git-repo called about . Then, create the empty file about/index.html . Stage and commit a snapshot. git...
Read more >
Introduction to Git rebase and force-push - GitLab Docs
This guide helps you to get started with rebasing, force-pushing, and fixing merge conflicts locally. Before diving into this document, make sure you...
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