Open Christian-Yang opened 7 years ago
例如,要在项目中取代这个字符串<%= BASE_URL =>
可以使用下面这个代码,运行成功了
{
test: /\.ts$/,
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /<%= BASE_URL =>/ig,
replacement: function (match, p1, offset, string) {
var mypath = ""+path.resolve(__dirname,'../dist');
console.log('path==========',mypath);
return 'woshiyangxuefenga';
}
}
]})
}
This allows for arbitrary strings to be replaced as part of the module build process. The original intent is to replace API keys in modules prior to deployment.
这允许任意字符串被替换为模块构建过程的一部分。 原来的意图是在部署之前替换模块中的API密钥。
API:
StringReplacePlugin.replace([nextLoaders: string], options, [prevLoaders: string])
你不是担心,如果一个字符串,没有被替换掉,这个时候就已经开始被ts loader替换掉了吗? 没事有这个nextLoades和prevLoaders