lavyun / postcss-path-replace

The postcss plugin, what can replace resource path in css.
2 stars 0 forks source link

PostCSS 8 #2

Open AlecRust opened 1 year ago

AlecRust commented 1 year ago

Any plans to update this to use PostCSS 8? 🙂

AlecRust commented 11 months ago

In case anyone finds it useful, you can create an inline PostCSS plugin to avoid use of this plugin e.g.

// Replace the webfont paths hardcoded in Font Awesome's CSS
const fixWebfontPaths = root => {
  root.walkDecls(decl => {
    decl.value = decl.value.replace(/\.\.\/webfonts\//g, '/_static/webfonts/')
  })
}

const css = await readFile('input.pcss')
const processed = await postcss([
  postcssImport(),
  postcssPresetEnv({ stage: 1 }),
  fixWebfontPaths
]).process(css, { from: 'input.pcss', to: 'output.css' })