# grunt-css-url-replace

> Grunt task to replace css urls with absolute path

Latest version **0.2.7** (published 2016-02-21) · 0 weekly downloads

## Install

```sh
npm install grunt-css-url-replace
pnpm add grunt-css-url-replace
yarn add grunt-css-url-replace
bun add grunt-css-url-replace
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.7 |
| Published | 2016-02-21 |
| First published | 2013-08-29 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.8.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Tom.Huang |
| Maintainers | tom21joy |
| Keywords | gruntplugin |

## Links

- npm: https://www.npmjs.com/package/grunt-css-url-replace
- Repository: https://github.com/nanjingboy/grunt-css-url-replace
- Issues: https://github.com/nanjingboy/grunt-css-url-replace/issues
- npm.io page: https://npm.io/package/grunt-css-url-replace

## Recent versions

- 0.2.7 (latest) — 2016-02-21
- 0.2.5 — 2015-05-30
- 0.2.3 — 2014-11-02
- 0.2.1 — 2014-10-27
- 0.1.9 — 2014-06-28
- 0.1.7 — 2014-05-29
- 0.1.5 — 2014-01-22
- 0.1.3 — 2013-09-05
- 0.1.1 — 2013-09-05
- 0.1.0 — 2013-08-29

## README

# grunt-css-url-replace

> Grunt task to replace css urls with absolute path

## Getting Started
This plugin requires Grunt `~0.4.5`

If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

```shell
npm install grunt-css-url-replace --save-dev
```

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

```js
grunt.loadNpmTasks('grunt-css-url-replace');
```

### Options

#### options.staticRoot
Type: `String`
Default value: `'public'`

The root static directory in your website

### Usage Examples

```js
grunt.initConfig({
  css_url_replace: {
    options: {
      staticRoot: 'public'
    },
    replace: {
      files: {
        'dest/build.css': ['css/application.css', 'css/users/default.css']
      }
    }
  }
});
```

In this example, imagine the following folder structure and css contents:

```
public
├── css
│   └─── application.css
|   └─── users
|        └─── default.css
├── images
|   └── baner.png
|   └── avatar.png
```

#### css/application.css
```css
  .baner{background-image:url("../images/baner.png");}
  .baner{background-image:url("../images/baner.png#test");}
  .http { background-image: url("http://somehost.com/image.png"); }
  .https_urls { background-image: url("https://somehost.com/image.png"); }
```

#### css/users/default.css
```css
  .avatar{background-image:url("../../images/avatar.png");}
  .avatar{background-image:url("../../images/avatar.png?name=test");}
  .data_urls { background-image: url('data:image/png:base64,0'); }
  .backslashes_urls { background-image: url('\images\e.png') }
```

#### the generated file dest/build.css is would be:
```css
  .baner{background-image:url("/images/baner.png");}
  .baner{background-image:url("/images/baner.png#test");}
  .http { background-image: url("http://somehost.com/image.png"); }
  .https_urls { background-image: url("https://somehost.com/image.png"); }
  .avatar{background-image:url("/images/avatar.png");}
  .avatar{background-image:url("/images/avatar.png?name=test");}
  .data_urls { background-image: url("data:image/png:base64,0"); }
  .backslashes_urls { background-image: url("/images/e.png") }
```

## Contributors
* [superbug](https://github.com/superbug)
* [Nehle](https://github.com/Nehle)

## License
* [MIT](https://github.com/nanjingboy/grunt-css-url-replace/blob/master/LICENSE-MIT)

---
_Source: https://npm.io/package/grunt-css-url-replace · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
