# css-fix-url-loader

> Webpack loader to transform URLs to other URLs on CSS.

Latest version **1.0.2** (published 2018-12-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install css-fix-url-loader
pnpm add css-fix-url-loader
yarn add css-fix-url-loader
bun add css-fix-url-loader
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2018-12-13 |
| First published | 2018-12-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alexander Pervushen |
| Maintainers | alexpua |
| Keywords | webpack, loader, webpack-loader, css, url, relative-url, absolute-url, relative-url |

## Links

- npm: https://www.npmjs.com/package/css-fix-url-loader
- Repository: https://github.com/studio-webb/css-fix-url-loader
- Homepage: https://github.com/studio-webb/css-fix-url-loader#readme
- Issues: https://github.com/studio-webb/css-fix-url-loader/issues
- npm.io page: https://npm.io/package/css-fix-url-loader

## Dependencies (1)

- [loader-utils](https://npm.io/package/loader-utils.md) ^1.1.0

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2018-12-13
- 1.0.1 — 2018-12-12

## README

<div align="center">
  <a href="https://github.com/webpack/webpack">
    <img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg">
  </a>
</div>

[![npm version](https://badge.fury.io/js/css-fix-url-loader.svg)](https://badge.fury.io/js/css-fix-url-loader) [![npm module downloads](https://img.shields.io/npm/dt/css-fix-url-loader.svg)](https://npmjs.org/package/css-fix-url-loader) [![Dependency Status](https://david-dm.org/studio-webb/css-fix-url-loader.svg)](https://david-dm.org/studio-webb/css-fix-url-loader) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

# css-fix-url-loader 

Webpack loader to transform URLs to other URLs in CSS.
Fork from [css-url-loader](https://github.com/keidrun/css-url-loader/)

## Description

Transform URLs to other URLs in the `url()`s in your CSS. You can change relative urls
to absolute urls, or absolute urls to relative urls, or you can change old urls to new urls that you want.

## Install

```bash
npm install --save-dev css-fix-url-loader
```

Or

```bash
yarn add --dev css-fix-url-loader
```

## Usage

### When you want to trasform `url(/assets/...)` to `url(https://domain/assets/...)`, the `webpack.config.js` is below

```javascript
module.exports = {
  ...
  module: {
    rules: [
      ...
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            'css-loader',
            {
              loader: 'css-fix-url-loader',
              query: {
                from: '/assets/',
                to: 'https://domain/assets/'
              }
            }
          ],
        }),
      },
      ...
    ],
  },
  plugins: [
    ...
    new ExtractTextPlugin('bundle.css'),
    ...
  ],
```

### When you want to trasform `url(/assets/...)` to `url(/dir/assets/...)`, the `webpack.config.js` is below

```javascript
module.exports = {
  ...
  module: {
    rules: [
      ...
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            'css-loader',
            {
              loader: 'css-fix-url-loader',
              query: {
                from: '/assets/',
                to: '/dir/assets/'
              }
            }
          ],
        }),
      },
      ...
    ],
  },
  plugins: [
    ...
    new ExtractTextPlugin('bundle.css'),
    ...
  ],
```

### When you want to trasform urls when only development, the `webpack.config.js` is below

```javascript
module.exports = {
  ...
  module: {
    rules: [
      ...
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            'css-loader',
            {
              loader: 'css-fix-url-loader',
              query: {
                from: '/assets/',
                to: '/tmp/assets/',
                env: 'development'
              }
            }
          ],
        }),
      },
      ...
    ],
  },
  plugins: [
    ...
    new ExtractTextPlugin('bundle.css'),
    ...
  ],
```

### When you want to trasform urls from absolute to relative, the `webpack.config.js` is below

```javascript
module.exports = {
  ...
  module: {
    rules: [
      ...
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            'css-loader',
            {
              loader: 'css-fix-url-loader',
              query: {
                from: '/images',
                to: path.resolve(__dirname, './src/images'),
                relative: true
              }
            }
          ],
        }),
      },
      ...
    ],
  },
  plugins: [
    ...
    new ExtractTextPlugin('bundle.css'),
    ...
  ],
```

## Options

| Option   | Description                                                                             | Required |
| -------- | :-------------------------------------------------------------------------------------- | :------: |
| from     | original url in url()                                                                   |    Y     |
| to       | transformed url                                                                         |    Y     |
| env      | value to control execution timing with `process.env.NODE_ENV`. Default is 'production'. |    N     |
| relative | if need to trasform urls from absolute to relative                                      |    N     |

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