1.0.4 • Published 4 years ago

postcss-path-replace v1.0.4

Weekly downloads
55
License
MIT
Repository
github
Last release
4 years ago

postcss-path-replace

Travis (.org) Coverage Status npm node NPM

usage

This plugin can replace the resource's url in your css:

{
  "postcss-path-replace" : {
    publicPath: "http://static.example.com",
    matched: "/static",
    mode: "append"
  }
}

before:

div {
  background: url(/static/img/header.png)
}

after:

div {
  background: url(http://static.example.com/static/img/header.png)
}

If mode was replace, the output css will be:

div {
  background: url(http://static.example.com/img/header.png)
}

OPTIONS

publicPath string

The plugin will use publicPath to replace the matched path, default is ''

matched string | RegExp

The matched path, it can be a RegExp:

{
  "postcss-path-replace" : {
    publicPath: '/static/module',
    mode: 'replace',
    matched: /\/static\/module-\d/g
  }
}

before:

div { background: url("/static/module-1/header.png") }

after:

div { background: url("/static/module/header.png") }

exec function

The custom execute function, it's the second argument of String.prototype.replace

options:

{
  matched: /\/static\/module-\d/g,
  exec: function (value) {
    const moduleIndex = value.split('-')[1]
    return value.split('-')[0] + '-' + (Number(moduleIndex) + 1)
  }
}

before:

div { background: url("/static/module-1/header.png") }

after:

div { background: url("/static/module-2/header.png") }

LISENCE

MIT