1. webpack-loader

1.1. loader template

const loaderUtils = require('loader-utils')
const cnchar = require('cnchar')
const trad = require('cnchar-trad')
cnchar.use(trad)

module.exports = function (source) {
  const option = loaderUtils.getOptions(this);
  let newSource = ''
  newSource = cnchar.convert.simpleToTrad(source)
  const optionKeys = Object.keys(option)
  optionKeys.length && optionKeys.forEach(key => {
    newSource = newSource.replace(new RegExp(key, 'g'), option[key])
  })
  return newSource
}

1.2. loader 参数

https://www.npmjs.com/package/loader-utils

const loaderUtils = require('loader-utils')

const option = loaderUtils.getOptions(this);
Copyright © tomgou 2022 all right reserved,powered by Gitbook该文章修订时间: 2023-08-28 17:33:23

results matching ""

    No results matching ""