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);