0.6.4 • Published 27 days ago

yyl-file-replacer v0.6.4

Weekly downloads
14
License
ISC
Repository
github
Last release
27 days ago

yyl-file-replacer

a file replace plugin for yyl

安装

npm i yyl-file-replacer --save

引入

const replacer = require('yyl-file-replacer')

usage

htmlPathMatch

enum MatchType {
  CSS_PATH = 'css-path',
  JS_PATH = 'js-path',
  HTML_PATH = 'html-path'
}
interface Replacer {
  htmlPathMatch(ctx: string, handle: (matchUrl: string, type: MatchType) => string): string
}

example

const { htmlPathMatch } = require('yyl-file-replacer')
const htmlStr = `
  <link rel="stylesheet" href="./link-href/1.css" type="text/css">
`
const r = []
htmlPathMatch(htmlStr, (matchUrl, type) => {
  r.push(matchUrl)
})
console.log(r) // [./link-href/1.css]

jsPathMatch

interface Replacer {
  jsPathMatch(ctx: string, handle: (matchUrl: string, type: MatchType.JS_PATH) => string): string
}

example

const { jsPathMatch } = require('yyl-file-replacer')
const jsStr = `
  const a = __url('path/to/js')
  const b = __html('path/to/html')
`
const r = []
jsPathMatch(jsStr, (url, type, q) => {
  r.push({url, type, q})
)
console.log(r) // [{ url: 'path/to/js', type: '__url', q: '\''}, { url: 'path/to/html', type: '__html', q: '\''}]

cssPathMatch

interface Replacer {
  cssPathMatch(ctx: string, handle: (matchUrl: string, type: MatchType.CSS_PATH) => string): string
}

example

const { cssPathMatch } = require('yyl-file-replacer')
const cssStr = `
  body { background: url(path/to/a) }
`
const r = []
cssPathMatch(cssStr, (matchUrl, type) => {
  r.push(matchUrl)
)
console.log(r) // [path/to/a]

版本信息

这里

0.6.4

27 days ago

0.6.3

5 months ago

0.6.2

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.0-beta1

1 year ago

0.5.0

1 year ago

0.4.4

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago