An open API service indexing awesome lists of open source software.

https://github.com/feflow/replace-text-loader

A webpack loader for replacing content text.
https://github.com/feflow/replace-text-loader

Last synced: 10 months ago
JSON representation

A webpack loader for replacing content text.

Awesome Lists containing this project

README

          

replace-text-loader

Install

```bash
npm i replace-text-loader
```

Usage

**webpack.config.js**
```js
module.exports = {
module: {
rules: [
{
test: /\.index.html$/,
use: [{
loader: 'replace-text-loader',
options: {
rules: [{
// inline script, 匹配所有的 需要inline的标签
// 并且替换为 ${require('raw-loader!babel-loader!../../node_modules/@tencent/report-whitelist')} 语法
pattern: /.*?<\/script>/gmi,
replacement: (source) => {
// 找到需要 inline 的包
const result = /${require('raw-loader!babel-loader!" + pkg + "')}";
}
}, {
// inline html, 匹配语法
pattern: //gmi,
replacement: (source) => {
// 找到需要 inline 的包
const result = //gmi.exec(source);
let path = result && result[1];
if (path && path[0] === '/') {
path = '../..' + path;
}

return "${require('raw-loader!" + path +"')}";
}
}]
}
}]
}
]
}
}
```