0.6.4 • Published 3 years ago

yyl-file-replacer v0.6.4

Weekly downloads
14
License
ISC
Repository
github
Last release
3 years 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

3 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.0-beta1

4 years ago

0.5.0

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago